Skip to content

Instantly share code, notes, and snippets.

@honbin
Created October 18, 2012 05:51
Show Gist options
  • Save honbin/3910091 to your computer and use it in GitHub Desktop.
Save honbin/3910091 to your computer and use it in GitHub Desktop.
# reference url: http://jp.rubyist.net/magazine/?0038-MapAndCollect#l2
#reduce for lisp
# (reduce (lambda (i j) (+ i j)) '(3 4 5 6))
#reduce for ruby
p [3, 4, 5, 6].reduce {|i, j| i + j } #=>18
#inject for smalltalk
# #(3 4 5 6) inject: 0 into: [:i :j | i + j ]
#inject for ruby
p [3, 4, 5, 6].inject(0) {|i, j| i + j } #=>18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment