Boiani
Tuesday, 6 August 2013
Ruby inject function
Ruby inject function
Why does the second one not return the same value as the first?
puts (3..5).map{|n| n**3}.inject{|sum,n| sum + n}
puts (3..5).inject{|sum,n| sum + n**3}
216 192
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment