✅✅Day - 6 JavaScript Challenge || Easy || O(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# 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    if(nums.length === 0) return init;\n    let val = 0;\n    for(let i = 0;i < nums.length;i++){\n        if(i === 0) val = fn(init,nums[i]);\n        else val = fn(val,nums[i]); \n    }\n    return val;\n};\n```
['JavaScript']