Skip to content

Instantly share code, notes, and snippets.

@avinashsivaraman
Forked from kentcdodds/curried-add.js
Created August 31, 2018 05:48
Show Gist options
  • Save avinashsivaraman/d05c7693dd35e2b9f9e8134a11a75c61 to your computer and use it in GitHub Desktop.
Save avinashsivaraman/d05c7693dd35e2b9f9e8134a11a75c61 to your computer and use it in GitHub Desktop.
// 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