Source: https://bigfrontend.dev/problem/implement-Array-prototype-map
// Map should be able to support// callback with// (element) =>// (element, index) =>// (element, index, array) =>// callback and thisArgArray.prototype.myMap = function(callback, thisArg) {const length = this.length;const newArr = new Array(length);for (let i = 0; i < length; i++) {// Handle empty indices i.e. Array(5) -> arr[0] = 1 arr[2] = undefinedif (i in this) {newArr[i] = callback.call(thisArg, this[i], i, this);}}return newArr;}console.log([1,2,3].myMap(num => num * 2));console.log([1,2,3].myMap((num, i) => num + i));const arr = new Array(5)arr[0] = 1arr[2] = undefinedarr[4] = nullconst callback = item => itemconsole.log(arr.myMap(callback));const arr2 = [1,2,3]const arr3 = [1,2,3]const callback2 = (item, i, array) => {array[1] = 4array[2] = 6return item}console.log([1,2,3].myMap(callback2))