From 7f47da1e5b5b1001c8b0b8b99d19ef76dd829c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Wed, 1 Feb 2023 10:33:17 +0200 Subject: [PATCH 1/5] line 16 --- 1-js/99-js-misc/03-currying-partials/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index d71ac23f87..ada42ca6a9 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -13,7 +13,7 @@ Currying doesn't call a function. It just transforms it. Let's see an example first, to better understand what we're talking about, and then practical applications. -We'll create a helper function `curry(f)` that performs currying for a two-argument `f`. In other words, `curry(f)` for two-argument `f(a, b)` translates it into a function that runs as `f(a)(b)`: +We'll create a helper function `curry(f)` that performs currying for a two-argument `f`. In other words, the `curry(f)` function receives the two-argument `f(a, b)`, and returns a function that runs as `f(a)(b)`: ```js run *!* From 42138bae3b598573865cecc1975f7b5a05e3f04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Wed, 1 Feb 2023 10:34:09 +0200 Subject: [PATCH 2/5] line 41 keeping consistency with line 20 --- 1-js/99-js-misc/03-currying-partials/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index ada42ca6a9..2a1e5d7bb5 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -38,7 +38,7 @@ alert( curriedSum(1)(2) ); // 3 As you can see, the implementation is straightforward: it's just two wrappers. -- The result of `curry(func)` is a wrapper `function(a)`. +- The result of `curry(f)` is a wrapper `function(a)`. - When it is called like `curriedSum(1)`, the argument is saved in the Lexical Environment, and a new wrapper is returned `function(b)`. - Then this wrapper is called with `2` as an argument, and it passes the call to the original `sum`. From 00fcb087b699fb0cd6a8494c1daf3a7611d473e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Fri, 3 Feb 2023 08:36:32 +0200 Subject: [PATCH 3/5] line 114 --- 1-js/99-js-misc/03-currying-partials/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index 2a1e5d7bb5..bcddfb5321 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -111,7 +111,7 @@ So: ## Advanced curry implementation -In case you'd like to get in to the details, here's the "advanced" curry implementation for multi-argument functions that we could use above. +In case you'd like to get into the details, here's the "advanced" curry implementation for multi-argument functions that we could use above. It's pretty short: From 9a09083a7ba726a5c6eefc01c11b5af91416dd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Fri, 3 Feb 2023 08:55:07 +0200 Subject: [PATCH 4/5] line 167 --- 1-js/99-js-misc/03-currying-partials/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index bcddfb5321..421d5b9993 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -164,7 +164,7 @@ function curried(...args) { When we run it, there are two `if` execution branches: -1. If passed `args` count is the same or more than the original function has in its definition (`func.length`) , then just pass the call to it using `func.apply`. +1. If passed `args` count is the same or more than the original function has in its definition (`func.length`), then just pass the call to it using `func.apply`. 2. Otherwise, get a partial: we don't call `func` just yet. Instead, another wrapper is returned, that will re-apply `curried` providing previous arguments together with the new ones. Then, if we call it, again, we'll get either a new partial (if not enough arguments) or, finally, the result. From f9975ac21fe82229f190a39c1b304c80e71dc77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Fri, 3 Feb 2023 09:31:31 +0200 Subject: [PATCH 5/5] added comment It might be obvious, but may be useful to briefly mention the arguments object here. --- 1-js/99-js-misc/03-currying-partials/article.md | 1 + 1 file changed, 1 insertion(+) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index 421d5b9993..9393527aad 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -120,6 +120,7 @@ function curry(func) { return function curried(...args) { if (args.length >= func.length) { + // args is an array-like object we can operate on return func.apply(this, args); } else { return function(...args2) {