Can someone please explain me solution 1 using for loop in detail. freeCodeCamp Challenge Guide: Implement map on a Prototype
I’m majorly struggling to understand the
newArray.push(callback(this[i], i, this)); part of the solution
why are there 3 parameters used inside the callback function here, this[i] indicates the current element, I get that, but why and how are i and this used??
I’d love a detailed explanation
Id go back and read the previous lesson real quick.
haha nvm chatgpt explained it to me lol, I was confused what would happen to the ‘i’ and ‘this’ cz we won’t be needing it in every function, and my dumbass didn’t realize the parameters will only be passed and not utilized
I’d be careful asking ChatGPT - it will give an answer but it sometimes reports wrong information or invents information.
It is up to the consumer of your map API if they need the index and the array map was called upon. As you are expected to implement the same API as the official map method it must pass the same arguments to the callback.