Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 496 Bytes

no-reduce.md

File metadata and controls

26 lines (17 loc) · 496 Bytes

Disallow the usage of Array#reduce

Array.reduce usually results in hard-to-read code. It can almost every time by replaced fith .map, .filter. Only in the rare case of summing up the array it is useful.

Use eslint-disable comment if you really need to use it.

This rule is not fixable.

Fail

const arr = [1, 2, 3, 4];

arr.reduce((acc, n) => {
	if (n > 2) acc = [...acc, n];
	return acc;
}, []);

Pass

const arr = [1, 2, 3, 4];

arr.filter((n) => n > 2);