Skip to content
Myr

More specs for Collection#toArray()

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

authored by visionmedia · committed by visionmedia · parent c0a15f2 · Browse files · 2 files+14 added−2 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+14 added−2 removed

  • tests:+8 added−0 removed
  • other:+6 added−2 removed

2 files+14 added−2 removed

modified:lib/express/collection.js+6 added-2 removed
257 unmodified lines
258 },259 260 /**261 * Convert a collection to a true array.262 * Works recursively263 *264 * @return {array}265 * @api public266 */267 268 toArray: function() {269 return this.reduce([], function(array, val){270 if (val instanceof Collection)271 array.push(val.toArray())272 else269 array.push(val)273 array.push(val)274 return array275 })276 },277
40 unmodified lines
318 chunks = [], chunk = [], i = 0 319 this.each(function(val, key){320 chunk.push(val)321 if (i++ > 0 && (i % size == 0 || i == len))318 chunks.push(chunk),322 chunks.push($(chunk)),323 chunk = []324 })325 return $(chunks)326 }
14 unmodified lines
modified:spec/spec.collection.js+8 added
207 unmodified lines
208 describe '#toArray()'209 it 'should return an array'210 $(['foo', 'bar']).keys().toArray().should.eql [0, 1]211 end212 213 it 'should work on nested collections'214 $([$(['foo']), $(['bar'])]).toArray().should.eql [['foo'], ['bar']]215 end216 217 it 'should work with objects'218 $({ foo: 'bar', baz: { name: 'wahoo' }}).toArray().should.eql ['bar', { name: 'wahoo' }]219 end220 end221 222 describe '#min()'223 it 'should return the min value'
19 unmodified lines