We’re preparing your current view and syncing the latest data.
Apply a Function Over an Array
gfgGiven an array of elements and a transformation function, apply the transformation to each element in the array and return a new array containing the transformed elements.
An array of elements and a transformation function.
A new array where each element is the result of applying the transformation function to the corresponding element in the input array.
Not provided.
Example 1
Input
arr = [1, 2, 3, 4], transformation = x -> x * 2
Output
[2, 4, 6, 8]
Explanation
Each element in the array is multiplied by 2.