Skip to content
Myr

Added Collection#{min,max}()

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

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

  • tests:+12 added−1 removed
  • other:+30 added−0 removed

2 files+42 added−1 removed

modified:lib/express/collection.js+30 added
245 unmodified lines
246 return this.reduce([], function(array, val){247 array.push(val)248 return array249 })250 },251 252 /**253 * Return the lowest number in the collection.254 *255 * @return {number}256 * @api public257 */258 259 min: function() {260 return this.reduce(null, function(min, val){261 return min === null ? val :262 val < min ? val :263 min264 })265 },266 267 /**268 * Return the largest number in the collection.269 *270 * @return {number}271 * @api public272 */273 274 max: function() {275 return this.reduce(null, function(max, val){276 return max === null ? val :277 val > max ? val :278 max279 })280 }281})282283/**
11 unmodified lines
modified:spec/spec.collection.js+12 added-1 removed
166 unmodified lines
167 168 describe '#grep()'169 it 'should select values matching the regular expression passed'170 var result = $(['foo', 'bar', 'foobar', 'baz']).grep(/foo(bar)?/)171 p(result)171 result.at(0).should.eql 'foo'172 result.at(1).should.eql 'foobar'173 result.at(2).should.be_null174 end
16 unmodified lines
191 $(['foo', 'bar']).keys().toArray().should.eql [0, 1]192 end193 end194 195 describe '#min()'196 it 'should return the min value'197 $([4,5,2,3,62]).min().should.eql 2198 end199 end200 201 describe 'max()'202 it 'should return the max value'203 $([3,5,2,3,43,2]).max().should.eql 43204 end205 end206 207 end208end