Skip to content
Myr

Added Collection#sum()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 36c2ce9 · Browse files · 2 files+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−0 removed

  • tests:+6 added−0 removed
  • other:+13 added−0 removed

2 files+19 added−0 removed

modified:lib/express/collection.js+13 added
336 unmodified lines
337 return this.arr.length338 return this.reduce(0, function(len){339 return ++len340 })341 },342 343 /**344 * Return the sum of numeric values in this collection.345 *346 * @return {number}347 * @api public348 */349 350 sum: function() {351 return this.reduce(0, function(sum, n){352 return sum + n353 })354 }355})356357/**
11 unmodified lines
modified:spec/spec.collection.js+6 added
246 unmodified lines
247 $([1,1,2,2,3,3]).chunk(4).toArray().should.eql [[1,1,2,2],[3,3]]248 end249 end250 251 describe '#sum()'252 it 'should return the sum of the numeric values'253 $([1,2,3]).sum().should.eql 6254 end255 end256 257 end258end