avoid double 'if' in Ox.forEach; minor documentation cleanup

This commit is contained in:
rolux 2013-01-03 15:56:55 +01:00
parent 67f744baaf
commit 0d9f689605

View file

@ -95,7 +95,7 @@ Ox.count = function(collection, value) {
Ox.every <f> Tests if every element of a collection satisfies a given condition Ox.every <f> Tests if every element of a collection satisfies a given condition
Unlike `Array.prototype.every`, `Ox.every` works for arrays, objects and Unlike `Array.prototype.every`, `Ox.every` works for arrays, objects and
strings. strings.
(collection, iterator) -> <b> True if every element passes the test (collection[, iterator]) -> <b> True if every element passes the test
collection <a|o|s> Collection collection <a|o|s> Collection
iterator <f> Iterator iterator <f> Iterator
value <*> Value value <*> Value
@ -173,23 +173,25 @@ Ox.forEach = function(collection, iterator, that) {
var i = 0, key, type = Ox.typeOf(collection); var i = 0, key, type = Ox.typeOf(collection);
if (type == 'object' || type == 'storage') { if (type == 'object' || type == 'storage') {
for (key in collection) { for (key in collection) {
if (Ox.hasOwn(collection, key)) { if (
if (iterator.call(that, collection[key], key, collection) === false) { Ox.hasOwn(collection, key)
&& iterator.call(that, collection[key], key, collection) === false
) {
break; break;
} }
}
i++; i++;
} }
} else { } else {
collection = Ox.toArray(collection); collection = Ox.toArray(collection);
for (i = 0; i < collection.length; i++) { for (i = 0; i < collection.length; i++) {
if (i in collection) { if (
if (iterator.call(that, collection[i], i, collection) === false) { i in collection
&& iterator.call(that, collection[i], i, collection) === false
) {
break; break;
} }
} }
} }
}
return i; return i;
}; };
@ -303,6 +305,8 @@ Ox.max <f> Returns the maximum value of a collection
3 3
> Ox.max('123') > Ox.max('123')
3 3
> Ox.max([])
-Infinity
@*/ @*/
Ox.max = function(collection) { Ox.max = function(collection) {
var ret, values = Ox.values(collection); var ret, values = Ox.values(collection);
@ -324,6 +328,8 @@ Ox.min <f> Returns the minimum value of a collection
1 1
> Ox.min('123') > Ox.min('123')
1 1
> Ox.min([])
Infinity
@*/ @*/
Ox.min = function(collection) { Ox.min = function(collection) {
var ret, values = Ox.values(collection); var ret, values = Ox.values(collection);
@ -468,7 +474,7 @@ Ox.objectToArray = function(object, key) {
Ox.forEach(object, function(v, k) { Ox.forEach(object, function(v, k) {
ret.push(Ox.extend(v, key, k)); ret.push(Ox.extend(v, key, k));
}); });
return ret return ret;
}; };
*/ */