mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Ensure _.find returns undefinedwhen a value cannot be found. [closes #15]
Former-commit-id: e6dc89f98a1df81e1b1d67c5e8f5725e4df3bc5a
This commit is contained in:
@@ -585,6 +585,7 @@
|
|||||||
* // => 2
|
* // => 2
|
||||||
*/
|
*/
|
||||||
var find = createIterator(baseIteratorOptions, {
|
var find = createIterator(baseIteratorOptions, {
|
||||||
|
'init': '',
|
||||||
'inLoop': 'if (callback(collection[index], index, collection)) return collection[index]'
|
'inLoop': 'if (callback(collection[index], index, collection)) return collection[index]'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
16
test/test.js
16
test/test.js
@@ -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');
|
QUnit.module('lodash.flatten');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user