Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
ecase raises an error if none of the test cases are satisfied. Writing the function like this just ensures it will fail loudly if it is called with an input other than one of the characters #\R or #\L. It's not very important here but this sort of thing could help detect a bug (your function is being called with an unexpected input) in a large application.
It's still O(n).
It's fine! Learning is what's important :)
Thanks @Kacarott, I really didn't know. Thanks for that lesson.
@geans You are overlooking one important thing.
map
does NOT go through the whole list. It creates a generator, which produces values one at a time, which feeds into the other functions, which short circuit.Here is proof:
man, just read my comment again: there is no difference in the present context...
:/
I believe that what @Ivry wrote is still valid, as this solution goes through the list twice because of the
map
(imagine a big list), however the problem can be solved in the first two items in case: one is True and the other False.So it's not "the best" practice. I mark as cleaver.
This comment is hidden because it contains spoiler information about the solution
Okay, so I am going to take a chance here and ask, does this method have any advantage... or the opposite?
@Ivry: you're comparing
O(2*n)
andO(n*2)
, saying they are different. They aren't.See above.
This comment is hidden because it contains spoiler information about the solution
Certainly not best practice because I was golfing... but since the declaration normally takes only 3 inputs, a 4th
any_other_value
added by the caller would crash it anyway with an unused argument error.thanks for the feedback. can you explain how it is unsafe?