Ensure _.find returns undefinedwhen a value cannot be found. [closes #15]

Former-commit-id: e6dc89f98a1df81e1b1d67c5e8f5725e4df3bc5a
This commit is contained in:
John-David Dalton
2012-05-25 15:15:16 -04:00
parent f81ede2fd6
commit 8a5eb89aa8
2 changed files with 17 additions and 0 deletions

View File

@@ -585,6 +585,7 @@
* // => 2
*/
var find = createIterator(baseIteratorOptions, {
'init': '',
'inLoop': 'if (callback(collection[index], index, collection)) return collection[index]'
});

View File

@@ -174,6 +174,22 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.find');
(function() {
var array = [1, 2, 3, 4];
test('should return found `value`', function() {
equal(_.find(array, function(n) { return n > 2; }), 3);
});
test('should return `undefined` if `value` is not found', function() {
equal(_.find(array, function(n) { return n == 5; }), undefined);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.flatten');
(function() {