Skip to content

Instantly share code, notes, and snippets.

@richardscarrott richardscarrott/add.js
Last active Apr 1, 2016

Embed
What would you like to do?
function add(val = 0, ...args) {
let sum = args.reduce((prev, curr) => {
return prev + curr;
}, val);
let ret = add.bind(this, sum);
ret.value = () => 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).value() === 24);
console.log(add(2, 3, 4)(5).add(4,6).value() + 5 === 29);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.