#106201Improve code readability JS Array.prototype.reduce
Description
const foo = [1, 2, 3];
// prints [ 1, 2, 3 ]
console.log(foo);
const bar = foo.reduce(
(foo /* <-- better name this 'fooAccumulator' */, node) => {
foo.push(node + 'reduced');
return foo;
},
[]
);
// prints [ 1, 2, 3 ]
console.log(foo);
// prints [ '1reduced', '2reduced', '3reduced' ]
console.log(bar);Reviews 2
Related issues 1
History 46
-
Gerrit Code Review pushed patch set 1 for main to change 88264 status
NewUnder Review <span data-processor="relativetime" data-value="2025-02-18T14:19:55+00:00" > 02/18/25, 14:19 </span> -
Ayke Halder changed subject
Improve code readability JS Object.reduceImprove code readability JS Array.prototype.reduce <span data-processor="relativetime" data-value="2025-02-18T14:27:35+00:00" > 02/18/25, 14:27 </span> -
Gerrit Code Review pushed patch set 2 for main to change 88264 <span data-processor="relativetime" data-value="2026-04-22T06:30:19+00:00" > 04/22/26, 06:30 </span>
-
Georg Ringer commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2026-11-12T21:02:33+00:00" > 11/12/26, 21:02 </span> -
Ayke Halder changed Related to #106182 <span data-processor="relativetime" data-value="2026-11-13T07:47:35+00:00" > 11/13/26, 07:47 </span>
-
Ayke Halder commented <span data-processor="relativetime" data-value="2026-11-13T08:24:24+00:00" > 11/13/26, 08:24 </span>
Georg Ringer wrote in #note-4:
> Using a unique name for the accumulator parameter ofArray.prototype.reduceis a matter of taste, and theno-shadowrule of typescript-eslint that would enforce it is not enabled in our ESLint configuration.I’m fine! This is just a decissio to make.
> The additional switch from spread to
push()only pays off for very large node lists and has been objected to in the review. The discussion is documented in the Gerrit change.About the very large node lists the algorithm implemented to enhance the nodes is computational expensive. Thereby for every node all the nodes in the array are “searched” to find the correct parent node…
With N nodes this becomes “N” searches over “N to 1” nodes until hit:
N * 0.5 N searches in total —> complexity O(n²)So even not having that many nodes makes the algorithm go slow.
For improvement see comment:
https://review.typo3.org/c/Packages/TYPO3.CMS/+/91284/comments/d11daad0_78c4b269
Closing this one as won’t do.
The change in Gerrit (https://review.typo3.org/c/Packages/TYPO3.CMS/+/88264) has been abandoned. Using a unique name for the accumulator parameter of
Array.prototype.reduceis a matter of taste, and theno-shadowrule of typescript-eslint that would enforce it is not enabled in our ESLint configuration. The additional switch from spread topush()only pays off for very large node lists and has been objected to in the review. The discussion is documented in the Gerrit change.If this is still valid for you in v15, please open a new issue and provide information how to reproduce it. Thanks!
hope you understand