Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Created April 17, 2014 21:57
Show Gist options
  • Save thatrubylove/11013851 to your computer and use it in GitHub Desktop.
Save thatrubylove/11013851 to your computer and use it in GitHub Desktop.
a-deeper-look-at-rubys-enumerable-example-1
numbers = [1,3,5,8,10,54,99]
cards = [5,3,4,6,2]
# get only the values where the distance is greater than 10
numbers.each_cons(2).select {|a,b| b-a>10 } #=> [[10, 54], [54, 99]]
# determine if the hand is a straight
cards.sort.each_cons(5).all? do |series|
(series.first..series.last).to_a == series
end #=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment