Skip to content

Latest commit

 

History

History
21 lines (13 loc) · 600 Bytes

prefer-flat-map.md

File metadata and controls

21 lines (13 loc) · 600 Bytes

Prefer .flatMap(…) over .map(…).flat()

Array#flatMap performs Array#map and Array#flat in one step.

This rule is fixable.

Fail

[1, 2, 3].map(i => [i]).flat();
[].concat(...foo.map((i) => i))

Pass

[1, 2, 3].flatMap(i => [i]);
[1, 2, 3].map(i => [i]).foo().flat();