Skip to main content
spacery
Source Link
Rimian
  • 38.7k
  • 17
  • 127
  • 119

Try this:

array.inject(0){ |sum, x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Try this:

array.inject(0){ |sum, x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Fixed link to Ruby documentation
Source Link
Fernando Briano
  • 7.8k
  • 13
  • 60
  • 75

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable DocumentationSee Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

added 106 characters in body
Source Link
David Wolever
  • 155.7k
  • 94
  • 365
  • 513

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Try this:

array.inject{|sum,x| sum + x }

See Ruby's Enumerable Documentation

Try this:

array.inject(0){|sum,x| sum + x }

See Ruby's Enumerable Documentation

(note: the 0 base case is needed so that 0 will be returned on an empty array instead of nil)

Switched to URL that always redirects to the current version of Ruby.
Source Link
Alan W. Smith
  • 25.6k
  • 5
  • 73
  • 101
Loading
a bit more info in linketh
Source Link
Rimian
  • 38.7k
  • 17
  • 127
  • 119
Loading
Source Link
zenazn
  • 14.4k
  • 2
  • 38
  • 26
Loading