Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created January 21, 2012 15:17
Show Gist options
  • Save miyohide/1653038 to your computer and use it in GitHub Desktop.
Save miyohide/1653038 to your computer and use it in GitHub Desktop.
配列の累積を求める
a = []
[1,2,3,4,5].inject(0) { |r,i| s = r + i ; a << s ; s }
puts a # => [1,3,6,10,15]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment