LoginSignup
0
0

More than 3 years have passed since last update.

Array#injectでArray#sumを代用

Posted at

Array#sumはRuby2.4から、それより前のバージョンでArray#sumっぽいことがしたい時はArray#injectで代用可能。

[1,2,3,4,5].inject(:+)

参考

http://rurema.clear-code.com/query:sum/
http://rurema.clear-code.com/2.3.0/method/Enumerable/i/inject.html

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0