Ox.every: add 'that' argument; make Ox.some work more like Ox.every
This commit is contained in:
parent
064a28da3d
commit
d6b7d2e949
1 changed files with 7 additions and 12 deletions
|
@ -111,9 +111,9 @@ Ox.every <f> Tests if every element of a collection satisfies a given condition
|
|||
> Ox.every([true, true, true])
|
||||
true
|
||||
@*/
|
||||
Ox.every = function(collection, iterator) {
|
||||
Ox.every = function(collection, iterator, that) {
|
||||
return Ox.filter(
|
||||
Ox.values(collection), iterator || Ox.identity
|
||||
Ox.values(collection), iterator || Ox.identity, that
|
||||
).length == Ox.len(collection);
|
||||
};
|
||||
|
||||
|
@ -506,16 +506,11 @@ Ox.some <f> Tests if one or more elements of a collection meet a given condition
|
|||
> Ox.some([false, null, 0, '', void 0])
|
||||
false
|
||||
@*/
|
||||
Ox.some = function(collection, iterator) {
|
||||
iterator = iterator || Ox.identity;
|
||||
var ret = false;
|
||||
Ox.forEach(collection, function(value, key, collection) {
|
||||
if (iterator(value, key, collection)) {
|
||||
ret = true;
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
Ox.some = function(collection, iterator, that) {
|
||||
iterator = iterator || Ox.identity;
|
||||
return Ox.forEach(collection, function(value, key, collection) {
|
||||
return !iterator.call(that, value, key, collection);
|
||||
}) < Ox.len(collection);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue