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 increases each value in the array by one.
Example 2:
1
2
3
4
5
Input:
arr = [1,2,3], fn = function plusI(n, i) { return n + i; }
Output:
[1,3,5]
Explanation: The function increases each value by the index it resides in.
Example 3:
1
2
3
4
5
Input:
arr = [10,20,30], fn = function constant() { return42; }
Output:
[42,42,42]
Explanation: The function always returns 42.