Last active
September 13, 2019 08:50
-
-
Save krishna2nd/97d09b7585697dc9ab912a6c3ab8c6e6 to your computer and use it in GitHub Desktop.
Revisions
-
krishna2nd revised this gist
Sep 13, 2019 . No changes.There are no files selected for viewing
-
krishna2nd created this gist
Sep 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ function sum() { let args = [...arguments]; if (args.length > 2) { let sumValue = 0; args.forEach(arg => { sumValue += arg; }); return sumValue; } if (args.length === 2) { return function() { return sum.apply(this, [...args, ...arguments]); }; } function single() { if (arguments.length === 0) { return sum.apply(this, args); } args = [...args, ...arguments]; return single; }; return single; } console.log(sum(2, 3, 4)); console.log(sum(2, 3)(4)); console.log(sum(2, 3, 4, 0, 1)); console.log(sum(2)(3)(4)()); console.log(sum(2)(3)(4)(0)(1)());