Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

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
 
PREVIOUS NEXT
Tagged: #ruby #inject
ADD COMMENT
Topic
Name
4+9 =