✅ 🌟 JAVASCRIPT SOLUTION ||🔥 BEATS 100% PROOF🔥|| 💡 CONCISE CODE ✅ || 🧑‍💻 BEGINNER FRIENDLY
Complexity
Time complexity:O(n)

Space complexity:O(1)
Code
# Complexity
- Time complexity:$$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
/**
 * @param {number[]} nums
 * @param {Function} fn
 * @param {number} init
 * @return {number}
 */
var reduce = function(nums, fn, init) {
    var val=0;
    if(nums.length>0) val=fn(init, nums[0]);
    else return init;
    for(var i=1;i<nums.length;i++)
    {
        val=fn(val, nums[i]);
    }
    return val;
};
```
['JavaScript']