Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strain exercise #366

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Add strain exercise #366

merged 2 commits into from
Oct 17, 2024

Conversation

ErikSchierboom
Copy link
Member

No description provided.

@colinleach
Copy link
Contributor

The exemplar is longer than it needs to be, though it took me a while to see how to improve it (too much Julia going on in my old, tired head recently). Suggested alternative:

keep <- function(input, fun) {
  if (is.null(input)) return(c())
  input[sapply(input, fun)]
}

I kind of feel there should be a one-liner using ifelse, but that struggles with a NULL on one branch and a vector on the other.

@colinleach
Copy link
Contributor

colinleach commented Oct 16, 2024

After writing my previous comment, I realized there is no need to test for null input. Only the input[sapply(input, fun)] is needed, so it is a one-liner.

A reminder that I should never underestimate R!

@ErikSchierboom
Copy link
Member Author

@colinleach That is really cool, but it goed against the instructions:

Keep your hands off that filter/reject/whatchamacallit functionality provided by your standard library!
Solve this one yourself using other basic tools instead.

@colinleach
Copy link
Contributor

OK, I see your point. A bit of a grey area in a context where this sort of thing is such a core part of the language, but not worth arguing about.

@colinleach colinleach merged commit b088f89 into main Oct 17, 2024
3 checks passed
@colinleach colinleach deleted the strain branch October 17, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants