Array Reduce Transformation
IntuitionHere we can use javascript reduce method to solve the questionApproachFirst define the output variable and assign it to 0.
Next applying the reduce met
# Intuition
Here we can use javascript reduce method to solve the question

# Approach
First define the output variable and assign it to 0.
Next applying the reduce method to nums array with two parameters accum and curr, and called the fn funtion with passing those arguments as fn(accum,curr) and assign the reduced result to output variable and return it.

Next creating the sum function and returning the aggregate result.

Now calling the reduce function with given arguments such nums,sum and 0 as
reduce(nums,sum,0)

# Complexity
- Time complexity: O(n)
- Space complexity: O(n)

# Code
```javascript []
/**
 * @param {number[]} nums
 * @param {Function} fn
 * @param {number} init
 * @return {number}
 */
var reduce = function (nums, fn, init) {
    let output = 0;
    output = nums.reduce((accum, curr) => fn(accum, curr), init)
    return output;
};
const nums = [1, 2, 3, 4];
const sum = (accum, curr) => {
    return accum + curr
}
reduce(nums, sum, 0);



```

Output:
![image.png](https://assets.leetcode.com/users/images/d793be0f-4e22-4310-8dba-0a41059687ae_1743057360.8961291.png)





['JavaScript']