Skip to content
Myr

Added Collection#all()

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

authored by visionmedia · committed by visionmedia · parent 5552e7e · Browse files · 2 files+30 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+30 added−0 removed

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

2 files+30 added−0 removed

modified:lib/express/collection.js+16 added
208 unmodified lines
209 return !! this.find(fn)210 },211 212 /**213 * Returns true if _fn_ always evaluates to true, otherwise214 * returns false.215 *216 * @param {function} fn217 * @return {bool}218 * @api public219 */220 221 all: function(fn) {222 return this.reduce(true, function(state, val, key){223 if (!state) throw $break224 return !! fn(val, key)225 })226 },227 228 /**229 * Select values matching _pattern_230 *231 * @param {regexp} pattern232 * @return {Collection}
80 unmodified lines
modified:spec/spec.collection.js+14 added
111 unmodified lines
112 result.should.eql 'raz'113 end114 end115 116 describe '#all()'117 it 'should return true when all evaluate to true'118 $(['foo', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_true119 end120 121 it 'should return false when any evaluate to false'122 $(['foo', 'bar', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_false123 end124 125 it 'should work with objects'126 $({ a: 'foo', b: 'foobar' }).all(function(val){ return val.charAt(0) == 'f' }).should.be_true127 end128 end129 130 describe '#any()'131 it 'should return true when found'132 $(['foo', 'bar']).any(function(val){ return val.charAt(0) == 'b' }).should.be_true133 end
94 unmodified lines