Polyfill of Array.map
Array.prototype.mapPolyfill = function (condition) {
const output = [];
this.forEach((item, index) => {
output[index] = condition(item, index, this);
});
return output;
};
const ans = [1, 2, 3, 4, 5].mapPolyfill((item) => item * 2);
console.log(ans);
// Output:
[2, 4, 6, 8, 10];