Skip to content

Instantly share code, notes, and snippets.

@avinashsivaraman
Forked from kentcdodds/curried-add.js
Created August 31, 2018 05:48
// finished version of https://youtu.be/yIcve5wIuAg
function add(...args) {
function curriedAdd(...args2) {
return add(...args, ...args2)
}
curriedAdd.value = args.reduce((total, current) => total + current)
return curriedAdd
}
console.assert(add(2, 5, 1).value === 8, 'does not work first case')
console.assert(add(2)(5)(1).value === 8, 'does not work for second case')
console.log(add(2)(5)(1).value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment