mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
perf: 2x performance gain preallocating the array
This commit is contained in:
parent
a40cefc528
commit
9e1077269a
@ -1,7 +1,7 @@
|
|||||||
export default function rangeMap(n: number, fn: (i: number) => any) {
|
export default function rangeMap(n: number, fn: (i: number) => any) {
|
||||||
const arr = []
|
const arr = new Array(n)
|
||||||
while (n > arr.length) {
|
for (let i = 0; i < n; i++) {
|
||||||
arr.push(fn(arr.length))
|
arr[i] = fn(i)
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user