From ac8a1720ef609883af9b202bdee520e2e88e534c Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 14 May 2023 11:00:17 +0200 Subject: [PATCH] =?UTF-8?q?problems(js):=20add=20=E2=80=9C2632.=20Curry?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- problems/curry.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 problems/curry.js diff --git a/problems/curry.js b/problems/curry.js new file mode 100644 index 0000000..be4abab --- /dev/null +++ b/problems/curry.js @@ -0,0 +1,19 @@ +/** + * @param {Function} fn + * @return {Function} + */ +var curry = function(fn) { + return function curried(...args) { + if (args.length >= fn.length) { + return fn.apply(this, args); + } + + return curried.bind(this, ...args); + }; +}; + +/** + * function sum(a, b) { return a + b; } + * const csum = curry(sum); + * csum(1)(2) // 3 + */