Created
February 21, 2013 00:23
-
-
Save kenrett/5000938 to your computer and use it in GitHub Desktop.
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 count_between(array, lower_bound, upper_bound) | |
if array.empty? | |
return 0 | |
end | |
array.each do |num| | |
if num >= lower_bound && num <= upper_bound | |
return num | |
else | |
return 0 | |
end | |
end | |
end | |
puts count_between([1,2,3], 0, 100) # => 3 | |
puts count_between([-10, 1, 2], 0, 100) # => 2 | |
puts count_between([10, 20, 30], 10, 30) # => 3 | |
puts count_between([], -100, 100) # => 0 | |
puts count_between([0], 0, 0) # => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment