Created
January 7, 2016 10:34
-
-
Save krokrob/f7913edb6bc19f5272c8 to your computer and use it in GitHub Desktop.
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
# REDUCE | |
# input: array | |
# output: single | |
numbers = [ 21, 36, 54, 18, 11] | |
sum = 0 | |
numbers.each do |number| | |
sum += number | |
end | |
puts sum | |
variance = numbers.map { |number| number*number }.reduce(:+) | |
puts variance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment