Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created February 21, 2013 00:23
Show Gist options
  • Save kenrett/5000938 to your computer and use it in GitHub Desktop.
Save kenrett/5000938 to your computer and use it in GitHub Desktop.
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