Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created August 20, 2012 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bunnymatic/3400227 to your computer and use it in GitHub Desktop.
Save bunnymatic/3400227 to your computer and use it in GitHub Desktop.
Trim an array to the next largest value given a value. Potentially useful for pagination needs.
def upto(arr,v); arr[0..arr.select{|x| x < v}.count] end
# usage
arr = 5.times.map{|x| 12 * (2**x)}
maxval = 26
upto(arr,maxval)
# => [12,24,48]
@loveybot
Copy link

Yay Ruby!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment