Reduce _.toArray and _.difference.

Former-commit-id: a0253006b0f38744314c449dbcffa15b67390910
This commit is contained in:
John-David Dalton
2012-10-23 18:08:09 -07:00
parent b0361183df
commit dfcde8171e

View File

@@ -2433,10 +2433,7 @@
* // => [2, 3, 4]
*/
function toArray(collection) {
if (!collection) {
return [];
}
if (typeof collection.length == 'number') {
if (collection && typeof collection.length == 'number') {
return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string')
? collection.split('')
: slice.call(collection);
@@ -2529,14 +2526,11 @@
* // => [1, 3, 4]
*/
function difference(array) {
var result = [];
if (!array) {
return result;
}
var index = -1,
length = array.length,
length = array ? array.length : 0,
flattened = concat.apply(ArrayProto, arguments),
contains = cachedContains(flattened, length);
contains = cachedContains(flattened, length),
result = [];
while (++index < length) {
var value = array[index];