Created
March 30, 2011 14:23
-
-
Save nazgob/894482 to your computer and use it in GitHub Desktop.
reduce howto
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
# do this | |
(5..10).reduce(0) do |sum, value| | |
sum + value | |
end | |
# not this | |
sum = 0 | |
(5..10).each do |value| | |
sum += value | |
end | |
sum | |
# m'okey? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment