From: Roelof Wobben Date: 2012-09-28T00:36:49+09:00 Subject: subtract values of a array --_5358db4a-3fa9-4b9b-a67a-6ab10e630e7e_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello=2C=20 I changed from ruby koans to rubymonks. Now I have to make a method which can substract any number of numbers. So I tried this=20 def subtract(*numbers) numbers.inject(0) { |sum=2C number| sum - number } end but that won't work subtract ( 4=2C5) gives -9 when -1 is the right answe= r. Can anyone give me a tip for a better answer.=20 Roelof = --_5358db4a-3fa9-4b9b-a67a-6ab10e630e7e_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello=2C

I changed from ruby koans to rubymonks.

Now I have = to make a method which can substract any number of numbers.

So I tri= ed this

def subtract(*numbers)
 =3B numbers.inject(0) { |sum= =2C number| sum - number }
end

but that won't work =3B subtra= ct ( 4=2C5) gives -9 =3B when -1 is the right answer.

Can anyone= give me a tip for a better answer.

Roelof



=
= --_5358db4a-3fa9-4b9b-a67a-6ab10e630e7e_--