Last active
September 24, 2015 20:50
-
-
Save airyboy/4b776d16975c5411a87a to your computer and use it in GitHub Desktop.
Ruby one-liners
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
#Sum a list of numbers: | |
(1..1000).inject { |sum, n| sum + n } | |
#Sum a list of numbers: | |
(1..1000).inject(&:+) | |
#Sum a list of numbers: | |
(1..1000).inject(:+) | |
#Filter a list of numbers: | |
[49, 58, 76, 82, 88, 90].partition { |n| n > 60 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment