re: Understanding reduce in JavaScript VIEW POST

re: "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...

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