Given an array arr containing only integers, and a function fn, return a new array where each element has been processed by fn. The new array should be returnedArray[i] = fn(arr[i], i). This problem should be solved without using JavaScript's built-in Array.map method.
// Example 1
Input: arr = [1,2,3], fn = function plusOne(n) { return n + 1; }
Output: [2,3,4]
Explanation:
const newArray = map(arr, plusOne); // [2,3,4]
The function adds one to each value in the array.
// Example 2
Input: arr = [1,2,3], fn = function plusI(n, i) { return n + i; }
Output: [1,3,5]
Explanation: The function adds the index to each value in the array.
function map(arr, fn){
const resultArr = []
for(let i=0; i<arr.length; i++){
resultArr.push( fn(arr[i],i) )
}
return resultArr
}