Skip to content
Myr

Added Collection#find()

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

authored by visionmedia · committed by visionmedia · parent 58d64ce · Browse files · 2 files+39 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+39 added−0 removed

  • tests:+19 added−0 removed
  • other:+20 added−0 removed

2 files+39 added−0 removed

modified:lib/express/collection.js+20 added
modified:spec/spec.collection.js+19 added
92 unmodified lines
93 $({ foo: 'bar' }).first().should.eql 'bar'94 end 95 end96 97 describe '#find()'98 it 'should return the value of the first match'99 var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'b' })100 result.should.eql 'bar'101 end102 103 it 'should return null when nothing matches'104 var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'a' })105 result.should.be_null106 end107 108 it 'should work with objects'109 var result = $({ foo: 'bar', baz: 'raz' }).find(function(val, key){110 return val.charAt(0) == 'r'111 })112 result.should.eql 'raz'113 end114 end115 116 describe '#slice()'117 it 'should return a slice of values'118 var collection = $(['foo', 'bar', 'baz']).slice(1, 3)119 collection.at(0).should.eql 'bar'
12 unmodified lines