Joel VanderWerf
3/25/2007 10:04:00 PM
Jesse Merriman wrote:
...
> # Test case from the lecture. Should print out 28.
> puts inner_product.call([[1,2,3], [6,5,4]])
> ---------------------------------------------------------------------
Ruby has its own way of doing things, not that there is anything wrong
with defining new ways:
[[1,2,3], [6,5,4]].transpose.map{|x,y|x*y}.inject{|s,x|s+x}
=> 28
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407