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
> Ox.every({a: 1, b: 2, c: 3}, function(v) { return v == 1; })
false
> Ox.every("foo", function(v) { return v == 'f'; })
> Ox.every('foo', function(v) { return v == 'f'; })
false
> Ox.every([true, true, true])
true
@*/
Ox.every = function(collection, iterator, that) {
return Ox.filter(
Ox.values(collection), iterator || Ox.identity, that
).length == Ox.len(collection);
iterator = iterator || Ox.identity;
return Ox.forEach(collection, function(value, key, collection) {
return !!iterator.call(that, value, key, collection);
}) == Ox.len(collection);
};
/*@