Pattern: Chained map().flat()
calls
Issue: -
Using flatMap()
is more efficient than chaining map()
and flat()
methods, as it avoids creating an intermediate array.
Example of incorrect code:
const bar = [1, 2, 3].map((i) => [i]).flat();
Example of correct code:
const bar = [1, 2, 3].flatMap((i) => [i]);