I’m trying to do exactly this, but with CoffeeScript:
# ruby:
items.map {|item| item.price * item.quantity }.reduce(:+)
What I have so far:
# coffeescript:
item.price * item.quantity for item in items
How can I sum all the items in the array? More generally, how can I perform any operation across all the items in the array (in Ruby this would be inject or reduce)?
Nevermind, I found it. It’s done with
reduce