Skip to content

Instantly share code, notes, and snippets.

@lumixraku
Last active September 11, 2020 16:01
Show Gist options
  • Save lumixraku/cb75e091b9e16e41acc6cdd919060665 to your computer and use it in GitHub Desktop.
Save lumixraku/cb75e091b9e16e41acc6cdd919060665 to your computer and use it in GitHub Desktop.
const curring = fn => {
const { length } = fn
const curried = (...args) => {
return (args.length >= length
? fn(...args)
: (...args2) => curried(...args.concat(args2)))
}
return curried
}
const listMerge = (a, b, c) => [a, b, c]
const curried = curring(listMerge)
console.log(curried(1)(2)(3)) // [1, 2, 3]
console.log(curried(1, 2)(3)) // [1, 2, 3]
console.log(curried(1, 2, 3)) // [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment