coffeescript

How can I add together the values of an array in CoffeeScript?


I have an array of numbers. How can I add them together the easiest way in CoffeeScript?


Solution

  • numbers = [1, 2, 3]
    sum = 0
    (sum += num for num in numbers) # add each number in array to sum