1 Line | 2 Line | Javascript | Typescript
Code\n1 Line\n\nJavascript\n\nvar reduce = function(nums, fn, init,i = 0) {\n    return (i === nums.length ? init : reduce(nums,fn,fn(init,nums[i]),i+1));\n};\n
# Code\n`1 Line`\n\n`Javascript`\n```\nvar reduce = function(nums, fn, init,i = 0) {\n    return (i === nums.length ? init : reduce(nums,fn,fn(init,nums[i]),i+1));\n};\n```\n`Typescript`\n```\nfunction reduce(nums: number[], fn: Fn, init: number,i: number = 0): number {\n    return i === nums.length ? init : reduce(nums,fn,fn(init,nums[i]),i + 1);\n};\n```\n\n`2 Line`\n\n`Javascript`\n```\nvar reduce = function(nums, fn, init) {\n    for(let i=0;i<nums.length;i++) init = fn(init,nums[i]);\n    return init;\n};\n```\n\n`Typescript`\n```\nfunction reduce(nums: number[], fn: Fn, init: number): number {\n    for(let i=0;i<nums.length;i++) init = fn(init,nums[i]);\n    return init;\n};\n```
['TypeScript', 'JavaScript']