re: Understanding reduce in JavaScript VIEW POST

FULL DISCUSSION
 

"I understand that a and b are supposed to be elements in the array, but how on earth does JavaScript know which one is which?"

I don't understand any of these questions you were asking when first analyzing reduce. First a and b were not elements in an array, but rather parameters, that is how they are figured out which are which. The person asking those questions, don't understand the difference between functions and arrays.

 

Well, b is an element of the array in the sense that it represents the element currently being processed in the array. Even MDN speaks of it that way (and even a would be an element in the array for the first invocation of the callback function in that particular case.)

At any rate, I think the root of our misunderstanding is that you seem to be taking my words as talking about their syntactic function (so to speak), while I'm talking about the value they represent and how reduce() deals with them.

code of conduct - report abuse