mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Use the new operator with the Array constructor.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
function arrayMap(array, iteratee) {
|
function arrayMap(array, iteratee) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array == null ? 0 : array.length
|
const length = array == null ? 0 : array.length
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result[index] = iteratee(array[index], index, array)
|
result[index] = iteratee(array[index], index, array)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import get from '../get.js'
|
|||||||
function baseAt(object, paths) {
|
function baseAt(object, paths) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = paths.length
|
const length = paths.length
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
const skip = object == null
|
const skip = object == null
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function baseIntersection(arrays, iteratee, comparator) {
|
|||||||
const includes = comparator ? arrayIncludesWith : arrayIncludes
|
const includes = comparator ? arrayIncludesWith : arrayIncludes
|
||||||
const length = arrays[0].length
|
const length = arrays[0].length
|
||||||
const othLength = arrays.length
|
const othLength = arrays.length
|
||||||
const caches = Array(othLength)
|
const caches = new Array(othLength)
|
||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
let array
|
let array
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import isArrayLike from '../isArrayLike.js'
|
|||||||
*/
|
*/
|
||||||
function baseMap(collection, iteratee) {
|
function baseMap(collection, iteratee) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const result = isArrayLike(collection) ? Array(collection.length) : []
|
const result = isArrayLike(collection) ? new Array(collection.length) : []
|
||||||
|
|
||||||
baseEach(collection, (value, key, collection) => {
|
baseEach(collection, (value, key, collection) => {
|
||||||
result[++index] = iteratee(value, key, collection)
|
result[++index] = iteratee(value, key, collection)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const nativeMax = Math.max
|
|||||||
function baseRange(start, end, step, fromRight) {
|
function baseRange(start, end, step, fromRight) {
|
||||||
let index = -1
|
let index = -1
|
||||||
let length = nativeMax(nativeCeil((end - start) / (step || 1)), 0)
|
let length = nativeMax(nativeCeil((end - start) / (step || 1)), 0)
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
result[fromRight ? length : ++index] = start
|
result[fromRight ? length : ++index] = start
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function baseSlice(array, start, end) {
|
|||||||
length = start > end ? 0 : ((end - start) >>> 0)
|
length = start > end ? 0 : ((end - start) >>> 0)
|
||||||
start >>>= 0
|
start >>>= 0
|
||||||
|
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result[index] = array[index + start]
|
result[index] = array[index + start]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function baseXor(arrays, iteratee, comparator) {
|
|||||||
return length ? baseUniq(arrays[0]) : []
|
return length ? baseUniq(arrays[0]) : []
|
||||||
}
|
}
|
||||||
let index = -1
|
let index = -1
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
const array = arrays[index]
|
const array = arrays[index]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function composeArgs(args, partials, holders, isCurried) {
|
|||||||
let leftIndex = -1
|
let leftIndex = -1
|
||||||
let rangeLength = nativeMax(argsLength - holdersLength, 0)
|
let rangeLength = nativeMax(argsLength - holdersLength, 0)
|
||||||
|
|
||||||
const result = Array(leftLength + rangeLength)
|
const result = new Array(leftLength + rangeLength)
|
||||||
const isUncurried = !isCurried
|
const isUncurried = !isCurried
|
||||||
|
|
||||||
while (++leftIndex < leftLength) {
|
while (++leftIndex < leftLength) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function composeArgsRight(args, partials, holders, isCurried) {
|
|||||||
const holdersLength = holders.length
|
const holdersLength = holders.length
|
||||||
const rightLength = partials.length
|
const rightLength = partials.length
|
||||||
const rangeLength = nativeMax(argsLength - holdersLength, 0)
|
const rangeLength = nativeMax(argsLength - holdersLength, 0)
|
||||||
const result = Array(rangeLength + rightLength)
|
const result = new Array(rangeLength + rightLength)
|
||||||
const isUncurried = !isCurried
|
const isUncurried = !isCurried
|
||||||
|
|
||||||
while (++argsIndex < rangeLength) {
|
while (++argsIndex < rangeLength) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function copyArray(source, array) {
|
|||||||
let index = -1
|
let index = -1
|
||||||
const length = source.length
|
const length = source.length
|
||||||
|
|
||||||
array || (array = Array(length))
|
array || (array = new Array(length))
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
array[index] = source[index]
|
array[index] = source[index]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
function mapToArray(map) {
|
function mapToArray(map) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const result = Array(map.size)
|
const result = new Array(map.size)
|
||||||
|
|
||||||
map.forEach((value, key) => {
|
map.forEach((value, key) => {
|
||||||
result[++index] = [key, value]
|
result[++index] = [key, value]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
function setToArray(set) {
|
function setToArray(set) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const result = Array(set.size)
|
const result = new Array(set.size)
|
||||||
|
|
||||||
set.forEach((value) => {
|
set.forEach((value) => {
|
||||||
result[++index] = value
|
result[++index] = value
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
function setToPairs(set) {
|
function setToPairs(set) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const result = Array(set.size)
|
const result = new Array(set.size)
|
||||||
|
|
||||||
set.forEach((value) =>
|
set.forEach((value) =>
|
||||||
result[++index] = [value, value]
|
result[++index] = [value, value]
|
||||||
|
|||||||
2
chunk.js
2
chunk.js
@@ -31,7 +31,7 @@ function chunk(array, size) {
|
|||||||
}
|
}
|
||||||
let index = 0
|
let index = 0
|
||||||
let resIndex = 0
|
let resIndex = 0
|
||||||
const result = Array(nativeCeil(length / size))
|
const result = new Array(nativeCeil(length / size))
|
||||||
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
result[resIndex++] = baseSlice(array, index, (index += size))
|
result[resIndex++] = baseSlice(array, index, (index += size))
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import isArrayLike from './isArrayLike.js'
|
|||||||
function invokeMap(collection, path, args) {
|
function invokeMap(collection, path, args) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const isFunc = typeof path == 'function'
|
const isFunc = typeof path == 'function'
|
||||||
const result = isArrayLike(collection) ? Array(collection.length) : []
|
const result = isArrayLike(collection) ? new Array(collection.length) : []
|
||||||
|
|
||||||
baseEach(collection, (value) => {
|
baseEach(collection, (value) => {
|
||||||
result[++index] = isFunc ? path.apply(value, args) : invoke(value, path, args)
|
result[++index] = isFunc ? path.apply(value, args) : invoke(value, path, args)
|
||||||
|
|||||||
2
times.js
2
times.js
@@ -30,7 +30,7 @@ function times(n, iteratee) {
|
|||||||
}
|
}
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = Math.min(n, MAX_ARRAY_LENGTH)
|
const length = Math.min(n, MAX_ARRAY_LENGTH)
|
||||||
const result = Array(length)
|
const result = new Array(length)
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result[index] = iteratee(index)
|
result[index] = iteratee(index)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user