Use the new operator with the Array constructor.

This commit is contained in:
John-David Dalton
2017-03-07 22:07:04 -08:00
parent 9260bd2f57
commit 5f2a03076d
16 changed files with 16 additions and 16 deletions

View File

@@ -9,7 +9,7 @@
function arrayMap(array, iteratee) {
let index = -1
const length = array == null ? 0 : array.length
const result = Array(length)
const result = new Array(length)
while (++index < length) {
result[index] = iteratee(array[index], index, array)

View File

@@ -11,7 +11,7 @@ import get from '../get.js'
function baseAt(object, paths) {
let index = -1
const length = paths.length
const result = Array(length)
const result = new Array(length)
const skip = object == null
while (++index < length) {

View File

@@ -21,7 +21,7 @@ function baseIntersection(arrays, iteratee, comparator) {
const includes = comparator ? arrayIncludesWith : arrayIncludes
const length = arrays[0].length
const othLength = arrays.length
const caches = Array(othLength)
const caches = new Array(othLength)
const result = []
let array

View File

@@ -11,7 +11,7 @@ import isArrayLike from '../isArrayLike.js'
*/
function baseMap(collection, iteratee) {
let index = -1
const result = isArrayLike(collection) ? Array(collection.length) : []
const result = isArrayLike(collection) ? new Array(collection.length) : []
baseEach(collection, (value, key, collection) => {
result[++index] = iteratee(value, key, collection)

View File

@@ -16,7 +16,7 @@ const nativeMax = Math.max
function baseRange(start, end, step, fromRight) {
let index = -1
let length = nativeMax(nativeCeil((end - start) / (step || 1)), 0)
const result = Array(length)
const result = new Array(length)
while (length--) {
result[fromRight ? length : ++index] = start

View File

@@ -21,7 +21,7 @@ function baseSlice(array, start, end) {
length = start > end ? 0 : ((end - start) >>> 0)
start >>>= 0
const result = Array(length)
const result = new Array(length)
while (++index < length) {
result[index] = array[index + start]
}

View File

@@ -18,7 +18,7 @@ function baseXor(arrays, iteratee, comparator) {
return length ? baseUniq(arrays[0]) : []
}
let index = -1
const result = Array(length)
const result = new Array(length)
while (++index < length) {
const array = arrays[index]

View File

@@ -21,7 +21,7 @@ function composeArgs(args, partials, holders, isCurried) {
let leftIndex = -1
let rangeLength = nativeMax(argsLength - holdersLength, 0)
const result = Array(leftLength + rangeLength)
const result = new Array(leftLength + rangeLength)
const isUncurried = !isCurried
while (++leftIndex < leftLength) {

View File

@@ -21,7 +21,7 @@ function composeArgsRight(args, partials, holders, isCurried) {
const holdersLength = holders.length
const rightLength = partials.length
const rangeLength = nativeMax(argsLength - holdersLength, 0)
const result = Array(rangeLength + rightLength)
const result = new Array(rangeLength + rightLength)
const isUncurried = !isCurried
while (++argsIndex < rangeLength) {

View File

@@ -10,7 +10,7 @@ function copyArray(source, array) {
let index = -1
const length = source.length
array || (array = Array(length))
array || (array = new Array(length))
while (++index < length) {
array[index] = source[index]
}

View File

@@ -7,7 +7,7 @@
*/
function mapToArray(map) {
let index = -1
const result = Array(map.size)
const result = new Array(map.size)
map.forEach((value, key) => {
result[++index] = [key, value]

View File

@@ -7,7 +7,7 @@
*/
function setToArray(set) {
let index = -1
const result = Array(set.size)
const result = new Array(set.size)
set.forEach((value) => {
result[++index] = value

View File

@@ -7,7 +7,7 @@
*/
function setToPairs(set) {
let index = -1
const result = Array(set.size)
const result = new Array(set.size)
set.forEach((value) =>
result[++index] = [value, value]

View File

@@ -31,7 +31,7 @@ function chunk(array, size) {
}
let index = 0
let resIndex = 0
const result = Array(nativeCeil(length / size))
const result = new Array(nativeCeil(length / size))
while (index < length) {
result[resIndex++] = baseSlice(array, index, (index += size))

View File

@@ -26,7 +26,7 @@ import isArrayLike from './isArrayLike.js'
function invokeMap(collection, path, args) {
let index = -1
const isFunc = typeof path == 'function'
const result = isArrayLike(collection) ? Array(collection.length) : []
const result = isArrayLike(collection) ? new Array(collection.length) : []
baseEach(collection, (value) => {
result[++index] = isFunc ? path.apply(value, args) : invoke(value, path, args)

View File

@@ -30,7 +30,7 @@ function times(n, iteratee) {
}
let index = -1
const length = Math.min(n, MAX_ARRAY_LENGTH)
const result = Array(length)
const result = new Array(length)
while (++index < length) {
result[index] = iteratee(index)
}