modify comment for Ox.slice, use Ox.slice

This commit is contained in:
rolux 2013-12-01 13:08:25 +01:00
parent ab3711cfad
commit 137124a903

View file

@ -138,7 +138,7 @@ Ox.filter = function(collection, iterator, that) {
} }
}); });
} else { } else {
ret = Ox.toArray(collection).filter(iterator, that); ret = Ox.slice(collection).filter(iterator, that);
if (type == 'string') { if (type == 'string') {
ret = ret.join(''); ret = ret.join('');
} }
@ -182,7 +182,7 @@ Ox.forEach = function(collection, iterator, that) {
i++; i++;
} }
} else { } else {
collection = Ox.toArray(collection); collection = Ox.slice(collection);
for (i = 0; i < collection.length; i++) { for (i = 0; i < collection.length; i++) {
if ( if (
i in collection i in collection
@ -289,7 +289,7 @@ Ox.map = function(collection, iterator, that) {
ret[key] = iterator.call(that, value, key, collection); ret[key] = iterator.call(that, value, key, collection);
}); });
} else { } else {
ret = Ox.toArray(collection).map(iterator); ret = Ox.slice(collection).map(iterator);
if (type == 'string') { if (type == 'string') {
ret = ret.join(''); ret = ret.join('');
} }
@ -430,7 +430,7 @@ Ox.shuffle = function(collection) {
}); });
} else { } else {
ret = []; ret = [];
Ox.toArray(collection).forEach(function(value, index) { Ox.slice(collection).forEach(function(value, index) {
var random = Math.floor(Math.random() * (index + 1)); var random = Math.floor(Math.random() * (index + 1));
ret[index] = ret[random]; ret[index] = ret[random];
ret[random] = value; ret[random] = value;
@ -459,10 +459,10 @@ Ox.slice <f> Alias for `Array.prototype.slice.call`
Ox.slice = Ox.toArray = function(collection, start, stop) { Ox.slice = Ox.toArray = function(collection, start, stop) {
return Array.prototype.slice.call(collection, start, stop); return Array.prototype.slice.call(collection, start, stop);
}; };
// IE8 returns an empty array if undefined is passed as stop // IE8 can't apply slice to NodeLists, returns an empty array if undefined is
// and an array of null values if a string is passed as value. // passed as stop and returns an array of null values if a string is passed as
// Firefox 3.6 returns an array of undefined values if a string // value. Firefox 3.6 returns an array of undefined values if a string is passed
// is passed as value. IE NodeLists may not work with slice. // as value.
if ( if (
Ox.slice([0]).length == 0 Ox.slice([0]).length == 0
|| Ox.slice('0')[0] === null || Ox.slice('0')[0] === null
@ -527,7 +527,7 @@ Ox.sum <f> Returns the sum of the values of a collection
@*/ @*/
Ox.sum = function(collection) { Ox.sum = function(collection) {
var ret = 0; var ret = 0;
collection = arguments.length > 1 ? Ox.toArray(arguments) : collection; collection = arguments.length > 1 ? Ox.slice(arguments) : collection;
Ox.forEach(collection, function(value) { Ox.forEach(collection, function(value) {
value = +value; value = +value;
ret += isFinite(value) ? value : 0; ret += isFinite(value) ? value : 0;