Skip to content

Instantly share code, notes, and snippets.

@sgentile
Last active December 20, 2015 05:39
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 sgentile/6079577 to your computer and use it in GitHub Desktop.
Save sgentile/6079577 to your computer and use it in GitHub Desktop.
Simple ruby map and reduce example
people = [{name:'Steve', age:43},{name:'Tyler', age:8}]
puts people.reduce(0) {|sum, value| sum + value[:age] } # 51
puts people.map {|n| n[:age]} # 43, 8
learn more! http://ruby-doc.org/core-2.0/Enumerable.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment