Created
April 17, 2014 21:57
-
-
Save thatrubylove/11013851 to your computer and use it in GitHub Desktop.
a-deeper-look-at-rubys-enumerable-example-1
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
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