Easy || Simple || Fast with detailed explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nCalling out the function for the whole array and returning the value init
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCalling out the function for the whole array and returning the value init if the array is empty.\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$ \n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {Function} fn\n * @param {number} init\n * @return {number}\n */\nvar reduce = function(nums, fn, init) {\n    let out=init;\n    if(nums.length === 0)\n        return init;\n    for(let i=0;i< nums.length;i++){\n        out= fn(out,nums[i])\n    }\n    return out;\n};\n```
['JavaScript']