diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 8c7a5562bd8..82a4f0c0db8 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3242,7 +3242,8 @@ "review-javascript-functional-programming": { "title": "JavaScript Functional Programming Review", "intro": [ - "Review the JavaScript Functional Programming concepts to prepare for the upcoming quiz." + "Before you are quizzed on functional programming concepts, you first need to review.", + "Open up this page to review concepts on functional programming, currying and more." ] }, "mjbe": { "title": "251", "intro": [] }, diff --git a/curriculum/challenges/english/25-front-end-development/review-javascript-functional-programming/6723d2c154dd19d0025f7cd9.md b/curriculum/challenges/english/25-front-end-development/review-javascript-functional-programming/6723d2c154dd19d0025f7cd9.md index 570806a04c5..c00aa294c7f 100644 --- a/curriculum/challenges/english/25-front-end-development/review-javascript-functional-programming/6723d2c154dd19d0025f7cd9.md +++ b/curriculum/challenges/english/25-front-end-development/review-javascript-functional-programming/6723d2c154dd19d0025f7cd9.md @@ -9,7 +9,54 @@ dashedName: review-javascript-functional-programming Review the concepts below to prepare for the upcoming quiz. +## Pure vs Impure Functions +- A pure function is one that always produces the same output for the same input and doesn't have any side effects. Its output depends only on its input, and it doesn't modify any external state. +- Impure functions have side effects, which are changes to the state of the program that are observable outside the function. + +## Functional programming + +- Functional Programming is an approach to software development that emphasizes the use of functions to solve problems, focusing on what needs to be done rather than how to do it. +- Functional programming encourages the use of techniques that help avoid side effects, such as using immutable data structures and higher-order functions. +- When used correctly, functional programming principles lead to cleaner and more maintainable code + +## Currying + +- Currying is a functional programming technique that transforms a function with multiple arguments into a sequence of functions, each taking a single argument. + +Here is an example of a regualr function vs a curried function: + +```js +// Regular function + +function average(a, b, c) { + return (a + b + c) / 3; +} + +// Curried function + +function curriedAverage(a) { + return function(b) { + return function(c) { + return (a + b + c) / 3; + }; + }; +} + +// Usage of curried function + +const avg = curriedAverage(2)(3)(4); +``` + +- Currying can be particularly powerful when working with functions that take many arguments. +- Currying makes your code more flexible and easier to reuse. +- You can use arrow functions to create curried functions more concisely: + +```js +const curriedAverage = a => b => c => (a + b + c) / 3; +``` + +- While currying can lead to more flexible and reusable code, it can also make code harder to read if overused. # --assignment--