From aebc0650f8fe0df6ec7df40204063ff79fcc8cde Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 22 Apr 2016 08:19:27 -0700 Subject: [PATCH] Simplify `_.concat`. --- lodash.js | 44 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/lodash.js b/lodash.js index 9f472f691..d379fdc14 100644 --- a/lodash.js +++ b/lodash.js @@ -456,30 +456,6 @@ return accumulator; } - /** - * Creates a new array concatenating `array` with `other`. - * - * @private - * @param {Array} array The first array to concatenate. - * @param {Array} other The second array to concatenate. - * @returns {Array} Returns the new concatenated array. - */ - function arrayConcat(array, other) { - var index = -1, - length = array.length, - othIndex = -1, - othLength = other.length, - result = Array(length + othLength); - - while (++index < length) { - result[index] = array[index]; - } - while (++othIndex < othLength) { - result[index++] = other[othIndex]; - } - return result; - } - /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -4592,8 +4568,8 @@ function wrapper() { var length = arguments.length, - index = length, - args = Array(length); + args = Array(length), + index = length; while (index--) { args[index] = arguments[index]; @@ -6053,16 +6029,16 @@ */ function concat() { var length = arguments.length, - array = castArray(arguments[0]); + args = Array(length ? length - 1 : 0), + array = arguments[0], + index = length; - if (length < 2) { - return length ? copyArray(array) : []; + while (index--) { + args[index - 1] = arguments[index]; } - var args = Array(length - 1); - while (length--) { - args[length - 1] = arguments[length]; - } - return arrayConcat(array, baseFlatten(args, 1)); + return length + ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)) + : []; } /**