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])
|
> Ox.every([true, true, true])
|
||||||
true
|
true
|
||||||
@*/
|
@*/
|
||||||
Ox.every = function(collection, iterator) {
|
Ox.every = function(collection, iterator, that) {
|
||||||
return Ox.filter(
|
return Ox.filter(
|
||||||
Ox.values(collection), iterator || Ox.identity
|
Ox.values(collection), iterator || Ox.identity, that
|
||||||
).length == Ox.len(collection);
|
).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])
|
> Ox.some([false, null, 0, '', void 0])
|
||||||
false
|
false
|
||||||
@*/
|
@*/
|
||||||
Ox.some = function(collection, iterator) {
|
Ox.some = function(collection, iterator, that) {
|
||||||
iterator = iterator || Ox.identity;
|
iterator = iterator || Ox.identity;
|
||||||
var ret = false;
|
return Ox.forEach(collection, function(value, key, collection) {
|
||||||
Ox.forEach(collection, function(value, key, collection) {
|
return !iterator.call(that, value, key, collection);
|
||||||
if (iterator(value, key, collection)) {
|
}) < Ox.len(collection);
|
||||||
ret = true;
|
|
||||||
return false; // break
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
Loading…
Reference in a new issue