JSFiddle - React, Tailwind, and code Playground

JavaScript

function map(func, array) {
    for (var i = 0; i < array.length; i++) {
         array[i] = func(array[i]);
    };
    return array;
};


function square(x) {
    return x*x;
};


console.log(map(square, [1,2,3,4]));
console.log(map(square, []));