content icon indicating copy to clipboard operation
content copied to clipboard

Change wording in Array.prototype.reduce()

Open stuymedova opened this issue 3 years ago • 1 comments

Description

Changed previousValue to accumulator.

Motivation

I believe the doc would be more clear and accurate if it stated that the first argument is an accumulator rather than the previous value. I personally had a misunderstanding based on that.

I encountered this while checking this set of interview questions which to my knowledge some companies use in their hiring process.

In addition, I've noticed the word accumulator is used on other pages of MDN: for TypedArray and reduceRight.

In case the PR is to be merged, an embedded interactive example need to be updated as well.

Additional details

Page URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

stuymedova avatar Nov 06 '22 11:11 stuymedova

For context, it was previously updated in https://github.com/mdn/content/pull/7484. cc @sideshowbarker

FWIW, I have a slight preference for accumulator. previousValue is described as "the value last passed to callbackFn", which is not fully accurate since it may also be initialValue. "reduce returns the value of accumulator" is also much easier to understand than "reduce returns the value of previousValue" (why does it return the previous value, not the current value?).

Josh-Cena avatar Nov 06 '22 17:11 Josh-Cena

Sofya, thanks much, and congrats on landing your first docs change here — welcome aboard 🎉

sideshowbarker avatar Nov 07 '22 03:11 sideshowbarker

Thank you :)

stuymedova avatar Nov 07 '22 11:11 stuymedova