4 different methods
\n/*\n * @param {number[]} nums\n * @param {Function} fn\n * @param {number} init\n * @return {number}\n /\n\n //Method 1\n\n// var reduce = function(nums, fn, 
\n/**\n * @param {number[]} nums\n * @param {Function} fn\n * @param {number} init\n * @return {number}\n */\n\n //Method 1\n\n// var reduce = function(nums, fn, init) {\n//     let val=init;\n//     for(let i=0;i<nums.length;i++){\n//         val=fn(val,nums[i]);\n//     }\n//     return val;\n// };\n\n// METHOD 2\n// var reduce = function(nums, fn, init) {\n//     let val=init;\n//     for(const i of nums){ //used \'of\' as we are accessing directly values\n//         val=fn(val,i);\n//     }\n//     return val;\n// };\n\n//METHOD 3\n// var reduce=function(nums,fn,init){\n//     let val=init;\n//     nums.forEach((n)=> val=fn(val,n));\n//     return val;\n// }\n\n//METHOD 4 directly use reduce function\nvar reduce =function(nums,fn,init){\n    return nums.reduce(fn,init)\n   \n}\n```
['JavaScript']