Skip to content

Commit fc99aef

Browse files
astorijeljharb
authored andcommitted
[guide] Use acc as reduce accumulator instead of memo to make it valid
In [this part of the `no-param-reassign` configuration](https://github.com/airbnb/javascript/blob/53b2d7d245ba4abefc0429bfda4a46f099b9ace5/packages/eslint-config-airbnb-base/rules/best-practices.js#L174-L175), `acc` is allowed to be mutated (rule [7.12](https://github.com/airbnb/javascript#functions--mutate-params), but `memo` is not. This causes the [rule 4.6 example](https://github.com/airbnb/javascript#arrays--callback-return) in the README to actually be invalid.
1 parent e9fff7a commit fc99aef

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,16 @@ Other Style Guides
404404
// good
405405
[1, 2, 3].map(x => x + 1);
406406
407-
// bad - no returned value means `memo` becomes undefined after the first iteration
408-
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
409-
const flatten = memo.concat(item);
410-
memo[index] = flatten;
407+
// bad - no returned value means `acc` becomes undefined after the first iteration
408+
[[0, 1], [2, 3], [4, 5]].reduce((acc, item, index) => {
409+
const flatten = acc.concat(item);
410+
acc[index] = flatten;
411411
});
412412
413413
// good
414-
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
415-
const flatten = memo.concat(item);
416-
memo[index] = flatten;
414+
[[0, 1], [2, 3], [4, 5]].reduce((acc, item, index) => {
415+
const flatten = acc.concat(item);
416+
acc[index] = flatten;
417417
return flatten;
418418
});
419419

0 commit comments

Comments
 (0)