From d4cf9deee624389c6eae9fbd42538de8bc47bd5d Mon Sep 17 00:00:00 2001 From: John Kennedy Date: Thu, 21 Jun 2018 09:38:21 +0100 Subject: [PATCH] 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 --- .../functional-programming.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json b/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json index fb4899651..1644da8c3 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json +++ b/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json @@ -1647,9 +1647,9 @@ "The arity of a function is the number of arguments it requires. Currying a function means to convert a function of N arity into N functions of arity 1.", "In other words, it restructures a function so it takes one argument, then returns another function that takes the next argument, and so on.", "Here's an example:", - "
//Un-curried function
function unCurried(x, y, z) {
  return x + y + z;
}

//Curried function
function curried(x) {
  return function(y) {
    return x + y;
  }
}
curried(1)(2) // Returns 3
", + "
//Un-curried function
function unCurried(x, y) {
  return x + y;
}

//Curried function
function curried(x) {
  return function(y) {
    return x + y;
  }
}
curried(1)(2) // Returns 3
", "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 curried function in the example above:", - "
// Call a curried function in parts:
var funcForY = curried(1);
var funcForZ = funcForY(2);
console.log(funcForZ(3)); // Prints 6
", + "
// Call a curried function in parts:
var funcForY = curried(1);
console.log(funcForY(2)); // Prints 3
", "Similarly, partial application can be described as applying a few arguments to a function at a time and returning another function that is applied to more arguments.", "Here's an example:", "
//Impartial function
function impartial(x, y, z) {
  return x + y + z;
}
var partialFn = impartial.bind(this, 1, 2);
partialFn(10); // Returns 13
", @@ -1698,4 +1698,4 @@ } } ] -} \ No newline at end of file +}