From: Dave Aronson Date: 2012-09-28T00:44:26+09:00 Subject: Re: subtract values of a array On Thu, Sep 27, 2012 at 11:36 AM, Roelof Wobben wrote: > def subtract(*numbers) > numbers.inject(0) { |sum, number| sum - number } > end > > but that won't work subtract ( 4,5) gives -9 when -1 is the right answer. You're overthinking it. Look at a simpler usage of inject. I find it useful to think of inject as injecting the operation between each element of the array it's given, and if it's given an argument as well (not an operation, one to treat as a starting value), then between that and the start as well. So what you've done there is tell it to do, essentially, 0 - 4 - 5. All you want is 4 - 5. How would you eliminate the "0 -" part? Hint: the argument is optional. -Dave -- Dave Aronson, T. Rex of Codosaurus, LLC... aka Available Secret-Cleared Ruby/Rails Freelancer (NoVa/DC/Remote); see http://www.Codosaur.us/.