π Prefer .flatMap(β¦) over .map(β¦).flat().
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
Array#flatMap performs Array#map and Array#flat in one step.
// β
const foo = bar.map(element => unicorn(element)).flat();
// β
const foo = bar.map(element => unicorn(element)).flat(1);
// β
const foo = bar.flatMap(element => unicorn(element));// β
const foo = bar.map(element => unicorn(element)).flat(2);// β
const foo = bar.map(element => unicorn(element)).foo().flat();// β
const foo = bar.flat().map(element => unicorn(element));