Skip to content

Instantly share code, notes, and snippets.

@mersanuzun
Created February 13, 2020 21:44
Show Gist options
  • Save mersanuzun/eead03c6d1c0297ba6d70aa5ad108ef9 to your computer and use it in GitHub Desktop.
Save mersanuzun/eead03c6d1c0297ba6d70aa5ad108ef9 to your computer and use it in GitHub Desktop.
#google #waits #for #you
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