Skip to content
Myr

Added Collection#sample()

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

authored by visionmedia · committed by visionmedia · parent 1ee61b4 · 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:+8 added−0 removed
  • other:+11 added−0 removed

2 files+19 added−0 removed

modified:lib/express/collection.js+11 added
386 unmodified lines
387 return this.merge({})388 },389 390 /**391 * Return the value of a random index.392 *393 * @return {mixed}394 * @api public395 */396 397 sample: function() {398 return this.at(Math.floor(Math.random() * this.length()))399 },400 401 /**402 * Convert collection to a string.403 *404 * @return {string}405 * @api public
19 unmodified lines
modified:spec/spec.collection.js+8 added
310 unmodified lines
311 b.arr.should.eql { foo: 'bar' }312 end313 end314 315 describe '#sample()'316 it 'should return a random value'317 var a = $([1,2,3,4]).sample()318 var b = $([1,2,3,4]).sample()319 a.should.not.eql b320 end321 end322 323 describe '#toString()'324 it 'should output [Collection ...] for array'325 $([1,2,3]).toString().should.eql '[Collection 1,2,3]'326 end
12 unmodified lines