Skip to content

Instantly share code, notes, and snippets.

@sekoyo
Last active September 7, 2016 13:10
Show Gist options
  • Save sekoyo/baf400ebd39a03bfa60c7b691d89844f to your computer and use it in GitHub Desktop.
Save sekoyo/baf400ebd39a03bfa60c7b691d89844f to your computer and use it in GitHub Desktop.
function add(...args) {
const sum = args.reduce((prev, curr) => prev + curr, 0);
const ret = add.bind(void 0, sum);
ret.value = ret.valueOf = () => sum;
ret.add = ret;
return ret;
}
console.log(add(1, 2).value() === 3);
console.log(add(1, 2)(3).value() === 6);
console.log(+add(2, 3, 4)(5)(4, 6) === 24);
console.log(add(2, 3, 4)(5).add(4,6) + 5 === 29);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment