Closed ErikSchierboom closed 1 month ago
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!
@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.
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.
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:
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.