JSFiddle - React, Tailwind, and code Playground

JavaScript

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

            function square(x) { return x * x; }
            var testAr = [1, 2, 3, 4];
            console.log(map(square, testAr));
            console.log(testAr);