Created
February 13, 2020 21:44
-
-
Save mersanuzun/eead03c6d1c0297ba6d70aa5ad108ef9 to your computer and use it in GitHub Desktop.
#google #waits #for #you
This file contains 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 characters
Function.prototype.toString = function() { | |
return this(); | |
} | |
const multiplier = (...args) => { | |
if (args.length === 0) { | |
return multiplier; | |
} | |
const rest = args.splice(1); | |
if (rest.length === 0 && Array.isArray(args[0])) { | |
return args[0][0]; | |
} | |
const result = rest.reduce((r, n) => r * n, Array.isArray(args[0]) ? args[0][0] : args[0]); | |
return (...args2) => multiplier([result], ...args2); | |
} | |
console.log(`${multiplier(2, 3, 4, 5, 6)} === 720`); | |
console.log(`${multiplier(2, 3)(4, 5, 6)} === 720`); | |
console.log(`${multiplier(2, 3)(4, 5, 6)(1)} === 720`); | |
console.log(`${multiplier(2)(3)(4)(5)(6, 1)} === 720`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment