mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 23:16: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) {
|
||||
const arr = []
|
||||
while (n > arr.length) {
|
||||
arr.push(fn(arr.length))
|
||||
const arr = new Array(n)
|
||||
for (let i = 0; i < n; i++) {
|
||||
arr[i] = fn(i)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user