From: "David A. Black" Date: 2009-07-22T08:01:05+09:00 Subject: Re: Standard Deviation question regarding EDOM errors --1926193751-1257340089-1248217233=:23297 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1257340089-1248217233=:23297" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1257340089-1248217233=:23297 Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Wed, 22 Jul 2009, Älphä Blüë wrote: >> The logic in the second snippet is wrong (assuming the logic in the >> product method is what you want). Try it with [1,2], for example, and >> you'll get 2 for the first one and 5 for the second. >> >> >> David > > Hi David, > > Please bear with me as my brain is a bit fried - been working on a lot > of complex issues all day long and so my mind is mush at this point. I > don't quite follow.. The method is calculating "product" as the sum of the squares (which I don't actually think is the product, is it?). The class's product method is calculating the product of all the elements of the array. So they're different. [1,2,3].inject {|a,b| a * b } # 6 total = 0.0 [1,2,3].each {|a| total += a * a } total # 14.0 David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN) --1926193751-1257340089-1248217233=:23297-- --1926193751-1257340089-1248217233=:23297--