Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit d4cf9de

Browse files
johnkennedy9147raisedadead
authored andcommitted
fix: sample code in intro to currying
Corrected the code sample that didnt work Amended uncurried example to better tie in with rest of code making the lesson more cohesive
1 parent 6de827c commit d4cf9de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

challenges/02-javascript-algorithms-and-data-structures/functional-programming.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,9 +1647,9 @@
16471647
"The <code>arity</code> of a function is the number of arguments it requires. <code>Currying</code> a function means to convert a function of N <code>arity</code> into N functions of <code>arity</code> 1.",
16481648
"In other words, it restructures a function so it takes one argument, then returns another function that takes the next argument, and so on.",
16491649
"Here's an example:",
1650-
"<blockquote>//Un-curried function<br>function unCurried(x, y, z) {<br>&nbsp;&nbsp;return x + y + z;<br>}<br><br>//Curried function<br>function curried(x) {<br>&nbsp;&nbsp;return function(y) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return x + y;<br>&nbsp;&nbsp;}<br>}<br>curried(1)(2) // Returns 3</blockquote>",
1650+
"<blockquote>//Un-curried function<br>function unCurried(x, y) {<br>&nbsp;&nbsp;return x + y;<br>}<br><br>//Curried function<br>function curried(x) {<br>&nbsp;&nbsp;return function(y) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return x + y;<br>&nbsp;&nbsp;}<br>}<br>curried(1)(2) // Returns 3</blockquote>",
16511651
"This is useful in your program if you can't supply all the arguments to a function at one time. You can save each function call into a variable, which will hold the returned function reference that takes the next argument when it's available. Here's an example using the <code>curried</code> function in the example above:",
1652-
"<blockquote>// Call a curried function in parts:<br>var funcForY = curried(1);<br>var funcForZ = funcForY(2);<br>console.log(funcForZ(3)); // Prints 6</blockquote>",
1652+
"<blockquote>// Call a curried function in parts:<br>var funcForY = curried(1);<br>console.log(funcForY(2)); // Prints 3</blockquote>",
16531653
"Similarly, <code>partial application</code> can be described as applying a few arguments to a function at a time and returning another function that is applied to more arguments.",
16541654
"Here's an example:",
16551655
"<blockquote>//Impartial function<br>function impartial(x, y, z) {<br>&nbsp;&nbsp;return x + y + z;<br>}<br>var partialFn = impartial.bind(this, 1, 2);<br>partialFn(10); // Returns 13</blockquote>",
@@ -1698,4 +1698,4 @@
16981698
}
16991699
}
17001700
]
1701-
}
1701+
}

0 commit comments

Comments
 (0)