# USAGE:
# given:
# <div class="price" data-amount="1">$1.00</div>
# <div class="price" data-amount="2">$2.00</div>
# > $('.price').get().sum (price) -> $(price).data('amount')
# > 3
Array::sum = (fn = (x) -> x) ->
@reduce ((a, b) -> a + fn b), 0
Sums elements of an array in a similar fashion as Ruby's `Array#sum` method
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.