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.
variable names are too long and the test only assert the result to be 58...
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, :+)
Yeah, String methods weren't allowed!
Yes, I also thought the same think. This solution absolutely is using string operation.
Should these solution not be failed as they use string methods?
Hey, you have nothing to apologize for! Your solution isn't the problem, it's the folks who upvote it who are the problem.
That's cool.. No worries.
The statement is in the description.
"The interesting part of this task is that you have to do it without string operation (hey, it's not really interesting otherwise)"
I did not see the stipulation. Sorry, but the code should work. Just check for syntax errors!
I've tried this. But it did not pass. I thought string operation were not allowed.
is a string with non numeric character.
Loading more items...