Created
August 20, 2012 03:32
-
-
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.
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 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay Ruby!!