Remove arrayPush in favor of spreading arguments.

This commit is contained in:
John-David Dalton
2017-02-21 10:34:25 -08:00
parent 0350d4904f
commit 56b7d339a6
5 changed files with 11 additions and 30 deletions

View File

@@ -1,20 +0,0 @@
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
let index = -1
const length = values.length
const offset = array.length
while (++index < length) {
array[offset + index] = values[index]
}
return array
}
export default arrayPush

View File

@@ -1,4 +1,3 @@
import arrayPush from './arrayPush.js'
import isFlattenable from './isFlattenable.js'
/**
@@ -26,7 +25,7 @@ function baseFlatten(array, depth, predicate, isStrict, result) {
// Recursively flatten arrays (susceptible to call stack limits).
baseFlatten(value, depth - 1, predicate, isStrict, result)
} else {
arrayPush(result, value)
result.push(...value)
}
} else if (!isStrict) {
result[result.length] = value

View File

@@ -1,4 +1,3 @@
import arrayPush from './arrayPush.js'
import getSymbols from './getSymbols.js'
import keys from '../keys.js'
@@ -11,7 +10,10 @@ import keys from '../keys.js'
*/
function getAllKeys(object) {
const result = keys(object)
return Array.isArray(object) ? result : arrayPush(result, getSymbols(object))
if (!Array.isArray(object)) {
result.push(...getSymbols(object))
}
return result
}
export default getAllKeys

View File

@@ -1,10 +1,8 @@
import arrayPush from './arrayPush.js'
import getSymbolsIn from './getSymbolsIn.js'
import keysIn from '../keysIn.js'
/**
* Creates an array of own and inherited enumerable property names and
* symbols of `object`.
* Creates an array of own and inherited enumerable property names and symbols of `object`.
*
* @private
* @param {Object} object The object to query.
@@ -12,7 +10,10 @@ import keysIn from '../keysIn.js'
*/
function getAllKeysIn(object) {
const result = keysIn(object)
return Array.isArray(object) ? result : arrayPush(result, getSymbolsIn(object))
if (!Array.isArray(object)) {
result.push(...getSymbolsIn(object))
}
return result
}
export default getAllKeysIn

View File

@@ -1,4 +1,3 @@
import arrayPush from './arrayPush.js'
import getSymbols from './getSymbols.js'
/* Built-in method references for those with the same name as other `lodash` methods. */
@@ -14,7 +13,7 @@ const nativeGetSymbols = Object.getOwnPropertySymbols
const getSymbolsIn = !nativeGetSymbols ? () => [] : object => {
const result = []
while (object) {
arrayPush(result, getSymbols(object))
result.push(...getSymbols(object))
object = Object.getPrototypeOf(Object(object))
}
return result