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.
You should never put any information which might give away the kata solution in the comments (without checking the "mark as having spoiler content" box) as they're visible to every one.
This comment is hidden because it contains spoiler information about the solution
Range
has a#sum
method, which will cover the 0 case on its own:(1..num).sum
works perfectlyRemoving every theoretical edge case isn't relevant and is not best pracitice and can even fall into bad practice. Staying pithy and readable is best practice. Much depends on the context whether you would use this or something else. If it's going to be used generally in a large application best to use a well worn solution or spend more than the 2 minutes creating method but you need to know the context of the method.
edge case fail (as pointed out, with an example fix) and bad runtime makes me seriously question the people calling it best practise. I would not like this in production code.
fix by doing
.reduce(0, :+)
Agreed.
There's no need for
return
here, as Ruby will return the evaluation of the last line automatically.Best practices? Really?
For some strange reason, I kept thinking we had to create a getChange function and was wondering why my code wasn't working. Just leaving this note here in case anyone else makes the same mistake I did.
Not sure which language you're using, but for Ruby it looks like the variable is $CHAR_TO_MORSE.
Anyone else having issues using Ruby? I have 2 valid solutions but both are returning "Submission timed out" errors when I run tests or submit. Both solutions work in my own Ruby environment.
Edit: Never mind. Just tried again and it's working now. Not sure what was going on.