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.
I like is_a? and instance_of? more than ===, it is implicit
very clever
using rescue to assure input is correct type
** Is it a correct or normal ruby way? **
Test.expect(solution((1..3).to_a, 1, 'a') == 2)
Test.expect(solution((1..3).to_a, -1, 'a') == 3, 'Using a negative index returned the wrong value.')
Test.expect(solution((1..3).to_a, -5, 'a') == 'a', 'Using a negative index returned the wrong value.')
Test.expect(solution((1..3).to_a, -3, 'a') == 1, 'Using a negative index returned the default value when it should have returned the first value within the array.')
Test.expect(solution((1..5).to_a, 10, 'a') == 'a', 'solution did not return default value when given an index that was out of range')
Test.expect(solution([nil, nil], 0, 'a') == nil, "solution([nil, nil], 0, 'a') should have returned nil but instead got #{solution([nil, nil], 0, 'a') || 'nil'}")
This comment is hidden because it contains spoiler information about the solution