Last active
December 28, 2015 08:59
-
-
Save RavensKrag/7476055 to your computer and use it in GitHub Desktop.
Ruby Enumeration interface, in reverse order
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..10).to_a # array of numbers 1-10 inclusive on both ends | |
numbers.detect {|i| i % 2 == 0} # first value divis by 2, starting from the front | |
numbers.reverse_each.detect {|i| i % 2 == 0 } # start from the rear instead |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment