From dfcde8171e96e3f8d41d4d43152abf7035dc000e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 23 Oct 2012 18:08:09 -0700 Subject: [PATCH] Reduce `_.toArray` and `_.difference`. Former-commit-id: a0253006b0f38744314c449dbcffa15b67390910 --- lodash.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index 9c8b13d75..059ce3129 100644 --- a/lodash.js +++ b/lodash.js @@ -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];