Created
August 3, 2019 15:20
-
-
Save ysm-dev/18d41628b5c9d3c72ba9bb4d8196051c to your computer and use it in GitHub Desktop.
Markdium-๐ป ํ๋ก ํธ์๋ ๋ฉด์ ์ง๋ฌธ - JS #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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