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, :+)
I'm getting this failure message,
Must allow to set code 'abnyyvuciwhtdi': no id given
Dispite all my test cases passing. What does that 'no id given' message mean?
My test cases ( that are all green )
Test.expect_error { Code.a }
Test.expect_no_error { Code.a = 10 }
Test.expect( Code.a == 10 )
Test.expect_error { Code.valghpf }
Test.expect_no_error { Code.valghpf = 22 }
Test.expect( Code.valghpf == 22 )
Test.expect_error { Code.nil }
Test.expect_no_error { Code.nil = 22 }
Test.expect( Code.nil == 22 )
This comment is hidden because it contains spoiler information about the solution