mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Use the new operator with the Array constructor.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
2
chunk.js
2
chunk.js
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user