faster Ox.every

This commit is contained in:
rlx 2016-02-20 14:38:04 +05:30
parent 75b5b76157
commit 8abbbd4791

View file

@ -106,15 +106,16 @@ Ox.every <f> Tests if every element of a collection satisfies a given condition
true true
> Ox.every({a: 1, b: 2, c: 3}, function(v) { return v == 1; }) > Ox.every({a: 1, b: 2, c: 3}, function(v) { return v == 1; })
false false
> Ox.every("foo", function(v) { return v == 'f'; }) > Ox.every('foo', function(v) { return v == 'f'; })
false false
> Ox.every([true, true, true]) > Ox.every([true, true, true])
true true
@*/ @*/
Ox.every = function(collection, iterator, that) { Ox.every = function(collection, iterator, that) {
return Ox.filter( iterator = iterator || Ox.identity;
Ox.values(collection), iterator || Ox.identity, that return Ox.forEach(collection, function(value, key, collection) {
).length == Ox.len(collection); return !!iterator.call(that, value, key, collection);
}) == Ox.len(collection);
}; };
/*@ /*@