Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created Feb 21, 2013
Embed
What would you like to do?
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