Skip to content

Instantly share code, notes, and snippets.

@ysm-dev
Created August 3, 2019 15:20
Show Gist options
  • Select an option

  • Save ysm-dev/18d41628b5c9d3c72ba9bb4d8196051c to your computer and use it in GitHub Desktop.

Select an option

Save ysm-dev/18d41628b5c9d3c72ba9bb4d8196051c to your computer and use it in GitHub Desktop.
Markdium-๐Ÿ’ป ํ”„๋ก ํŠธ์—”๋“œ ๋ฉด์ ‘ ์งˆ๋ฌธ - JS #4
function curry(fn) {
if (fn.length === 0) {
return fn
}
function _curried(depth, args) {
return function(newArgument) {
if (depth - 1 === 0) {
return fn(...args, newArgument)
}
return _curried(depth - 1, [...args, newArgument])
}
}
return _curried(fn.length, [])
}
function add(a, b) {
return a + b
}
var curriedAdd = curry(add)
var addFive = curriedAdd(5)
var result = [0, 1, 2, 3, 4, 5].map(addFive) // [5, 6, 7, 8, 9, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment