Answers for "inject method in ruby"

C
2

ruby inject

[1, 2, 3].inject { |sum, number| sum + number} # 6
# 1 + 2 = 3
# 3 + 3 = 6 

[1, 2, 3].inject(2) { |sum, number| sum + number} # 8
# 2 + 1 = 3
# 3 + 2 = 5
# 5 + 3 = 8
Posted by: Guest on October-14-2021
0

What does inject in ruby do

[3, 6, 10, 13].inject(:+) => (((3 + 6) + 10) + 13) => 32
Posted by: Guest on July-10-2020

Code answers related to "C"

Browse Popular Code Answers by Language