Polyfill: map( )
Difficulty: easy
Implement Array.prototype.myMap, a version of Array.prototype.map.
For every existing item in the array, call the callback and place the returned value at the same index in a new array.
Requirements
- Return a new array and do not mutate the original.
- Call the callback with
value,index, and the original array. - Throw a
TypeErrorwhen callback is not a function. - Preserve sparse array holes like native
map.