Skip to content

Instantly share code, notes, and snippets.

@JSerZANP
Last active August 16, 2020 08:38
Show Gist options
  • Save JSerZANP/de211b3c72a8ae4b5c9ea6503896293c to your computer and use it in GitHub Desktop.
Save JSerZANP/de211b3c72a8ae4b5c9ea6503896293c to your computer and use it in GitHub Desktop.
bfe.dev #1
const join = (a, b, c) => {
return `${a}_${b}_${c}`
}
const curriedJoin = curry(join)
curriedJoin(1, 2, 3) // '1_2_3'
curriedJoin(1)(2, 3) // '1_2_3'
curriedJoin(1, 2)(3) // '1_2_3'
function curry(func) {
return function curried(...args) {
// 1. if enough args, call func
// 2. if not enough, bind the args and wait for new one
if (args.length >= func.length) {
return func.apply(this, args)
} else {
return curried.bind(this, ...args)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment