Skip to content
Myr

Added Collection#toString()

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

authored by visionmedia · committed by visionmedia · parent 16ef731 · Browse files · 2 files+25 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+25 added−0 removed

  • tests:+14 added−0 removed
  • other:+11 added−0 removed

2 files+25 added−0 removed

modified:lib/express/collection.js+11 added
349 unmodified lines
350 sum: function() {351 return this.reduce(0, function(sum, n){352 return sum + n353 })354 },355 356 /**357 * Convert collection to a string.358 *359 * @return {string}360 * @api public361 */362 363 toString: function() {364 return '[Collection ' + this.arr + ']'365 }366})367368/**
11 unmodified lines
modified:spec/spec.collection.js+14 added
252 unmodified lines
253 $([1,2,3]).sum().should.eql 6254 end255 end256 257 describe '#toString()'258 it 'should output [Collection ...] for array'259 $([1,2,3]).toString().should.eql '[Collection 1,2,3]'260 end261 262 it 'should output [Collection [object Object]] for object'263 $({ foo: "bar" }).toString().should.eql '[Collection [object Object]]'264 end265 266 it 'should output [Collection [[Collection ...]]] for nested collections'267 $([$([1,2,3])]).toString().should.eql '[Collection [Collection 1,2,3]]'268 end269 end270 271 end272end