Skip to content
Myr

Added Collection#join()

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

authored by visionmedia · committed by visionmedia · parent 67a68b4 · Browse files · 2 files+26 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+26 added−0 removed

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

2 files+26 added−0 removed

modified:lib/express/collection.js+12 added
99 unmodified lines
100 return this101 },102 103 /**104 * Join a collection with the given _str_ or ", ".105 *106 * @param {string} str107 * @return {string}108 * @api public109 */110 111 join: function(str) {112 return this.toArray().join(str || ', ')113 },114 115 /**116 * Iterate with _memo_ using callback _fn_.117 * The _memo_ object is passed as the first 118 * argument, and the return value of _fn_ becomes119 * the value of _memo_ providing a functional
389 unmodified lines
modified:spec/spec.collection.js+14 added
381 unmodified lines
382 $([1,2,3]).reverse().toArray().should.eql [3,2,1]383 end384 end385 386 describe '#join()'387 it 'should join a collection with ", " by default'388 $([1,2,3]).join().should.eql '1, 2, 3'389 end390 391 it 'should join with an arbitrary string'392 $([1,2,3]).join(' ').should.eql '1 2 3'393 end394 395 it 'should work with objects'396 $({ foo: 'bar', baz: 'raz' }).join(' ').should.eql 'bar raz'397 end398 end399 400 describe '#toString()'401 it 'should output [Collection ...] for array'402 $([1,2,3]).toString().should.eql '[Collection 1,2,3]'403 end
12 unmodified lines