In various situations, array methods are best avoided, because they create an intermediate array for no benefit. Typically this is the use of array.map()
or array.filter()
followed by direct iteration or another array method.
array.map(fn1).map(fn2)
array.filter(fn1).filter(fn2)
array.map(fn1).forEach(fn2)
array.filter(fn1).forEach(fn2)
array.map(fn1).reduce(fn2)
array.filter(fn1).reduce(fn2)
array.filter(fn1).find(fn2)
for (const item of array.map(fn1)) {
fn2(item)
}
for (const item of array.filter(fn1)) {
fn2(item)
}
array.map(item => fn2(fn1(item)))
array.filter(item => fn1(item) && fn2(item))
array.forEach(item => {
fn2(fn1(item))
})
array.forEach((item) => {
if (fn1(item)) {
fn2(item)
}
})
array.reduce((acc, item) => {
return fn2(acc, fn1(item))
})
array.reduce((acc, item) => {
if (fn1(item)) {
return fn2(acc, item)
}
return acc
})
array.find((item) => fn1(item) && fn2(item))
for (const value of array) {
const item = fn1(value)
fn2(item)
}
for (const item of array) {
if (!fn1(item)) {
continue
}
fn2(item)
}
This could be autofixable.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too