Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created January 7, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krokrob/f7913edb6bc19f5272c8 to your computer and use it in GitHub Desktop.
Save krokrob/f7913edb6bc19f5272c8 to your computer and use it in GitHub Desktop.
# 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