Last active
August 29, 2015 13:58
-
-
Save kh0p/10003156 to your computer and use it in GitHub Desktop.
`NoMethodError: undefined method `+' for nil:NilClass` why?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scoreThrows(radiuses) | |
mapd = Array.new | |
radiuses.each do |x| | |
mapd << 10 if (x < 5) && (x >= 0) | |
mapd << 5 if (x <= 10) && (x >= 5) | |
mapd << 0 if (x > 10) | |
end | |
out = mapd.reduce(:+) | |
radiuses.all? { |x| x <= 5 == true } ? out += 100 : out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"You've just recently been hired to calculate scores for a Dart Board game!
Scoring specifications:
0 points - radius above 10
5 points - radius between 5 and 10 inclusive
10 points - radius less than 5
If all radiuses are less than 5, award 100 BONUS POINTS!
Write a function that accepts an array of radiuses (can be integers and/or floats),
and returns a total score using the above specification.
An empty array should return 0.
Examples:
scoreThrows( [1, 5, 11] ) => returns 15
scoreThrows( [15, 20, 30] ) => returns 0
scoreThrows( [1, 2, 3, 4] ) => returns 140" - http://www.codewars.com/dojo/katas/525dfedb5b62f6954d000006/train/ruby
^ Every test: passed.
^
NoMethodError: undefined method '<' for nil:NilClass
So how am I getting
NoMethodError: undefined method '+' for nil:NilClass
, and how should I handle it?