Polyfill: map()

EasyAmazonByteDanceApple

Prompt

Imagine the JavaScript array method .map() does not exist. Implement a myMap method on Array.prototype that works like the native .map().

Match these native details: accept an optional thisArg second argument, skip empty slots in sparse arrays (leaving them empty in the result), and stop at the array's original length even if the callback adds elements.