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.
Thinking about it, I'm pretty sure you are right. It would only unfluence the result before the summation (0 included or not).
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
It would be nice to specify what do with empty keys or values. That is, should the string
return
{"foo": "", "bar": "baz"}
or just{"bar": "baz"}
? I implemented the former behavior, but I have seen other solutions that do the latter. I think it would be good to have a test case that demands the one or the other.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
While this solution works for free-standing functions as tested in this Kata, it would fall apart when applied to object methods. Consider this test case:
This would fail with
expected NaN to equal 8
as the solution bindsthis
to the value it had at the time of the call to wrap, rather than torect
at the time of the call of the wrapper.This comment is hidden because it contains spoiler information about the solution
I have almost the same answer, but with an explicit
return 1 if exponent == 0
. The|| 1
trick is pretty clever, I would never have thought of that!has_key?
is generally considered deprecated andkey?
is preferred. See this comment of Ruby's creator Matz.