mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Merge branch 'underscore.any' of https://github.com/shinuza/underscore
This commit is contained in:
@@ -137,12 +137,15 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('collections: any', function() {
|
test('collections: any', function() {
|
||||||
|
var nativeSome = Array.prototype.some;
|
||||||
|
Array.prototype.some = null;
|
||||||
ok(!_.any([]), 'the empty set');
|
ok(!_.any([]), 'the empty set');
|
||||||
ok(!_.any([false, false, false]), 'all false values');
|
ok(!_.any([false, false, false]), 'all false values');
|
||||||
ok(_.any([false, false, true]), 'one true value');
|
ok(_.any([false, false, true]), 'one true value');
|
||||||
ok(!_.any([1, 11, 29], function(num){ return num % 2 == 0; }), 'all odd numbers');
|
ok(!_.any([1, 11, 29], function(num){ return num % 2 == 0; }), 'all odd numbers');
|
||||||
ok(_.any([1, 10, 29], function(num){ return num % 2 == 0; }), 'an even number');
|
ok(_.any([1, 10, 29], function(num){ return num % 2 == 0; }), 'an even number');
|
||||||
ok(_.some([false, false, true]), 'aliased as "some"');
|
ok(_.some([false, false, true]), 'aliased as "some"');
|
||||||
|
Array.prototype.some = nativeSome;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('collections: include', function() {
|
test('collections: include', function() {
|
||||||
|
|||||||
@@ -181,15 +181,15 @@
|
|||||||
// Determine if at least one element in the object matches a truth test.
|
// Determine if at least one element in the object matches a truth test.
|
||||||
// Delegates to **ECMAScript 5**'s native `some` if available.
|
// Delegates to **ECMAScript 5**'s native `some` if available.
|
||||||
// Aliased as `any`.
|
// Aliased as `any`.
|
||||||
var any = _.some = _.any = function(obj, iterator, context) {
|
var any = _.some = _.any = function (obj, iterator, context) {
|
||||||
iterator || (iterator = _.identity);
|
iterator = iterator || _.identity;
|
||||||
var result = false;
|
var result = false;
|
||||||
if (obj == null) return result;
|
if (obj == null) return result;
|
||||||
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
||||||
each(obj, function(value, index, list) {
|
each(obj, function (value, index, list) {
|
||||||
if (result = iterator.call(context, value, index, list)) return breaker;
|
if (result |= iterator.call(context, value, index, list)) return breaker;
|
||||||
});
|
});
|
||||||
return result;
|
return !!result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Determine if a given value is included in the array or object using `===`.
|
// Determine if a given value is included in the array or object using `===`.
|
||||||
|
|||||||
Reference in New Issue
Block a user