mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(curriculum): add JavaScript Functional Programming quiz (#56497)
Co-authored-by: Naomi the Technomancer <accounts+github@nhcarrigan.com>
This commit is contained in:
+133
-100
@@ -17,439 +17,472 @@ Answer all of the questions below correctly to pass the quiz.
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a pure function?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
A function that modifies global variables
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
A function that prints to the console
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
A function that changes its behavior based on external factors
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
A function that always returns the same output for the same input and produces no side effects
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is a characteristic of a pure function?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
It has side effects
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
It relies on global state
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
It modifies its input parameters
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Its output depends solely on its input arguments
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a side effect in functional programming?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
An unexpected error in the code
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
A function that takes too long to execute
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
A recursive function call
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
A change in program state or interaction with the outside world
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is an example of a side effect?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Returning a value from a function
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Creating a new object within a function
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Using a local variable
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Writing to a file
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is currying in functional programming?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
A technique for cooking functions
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
A method for optimizing recursive functions
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
A way to combine multiple functions into one
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
The process of transforming a function with multiple arguments into a sequence of functions, each with a single argument
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
In the context of pure functions, what does "referential transparency" mean?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
The function's code is visible to other parts of the program
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
The function references external variables transparently
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
The function's name clearly indicates its purpose
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
The function can be replaced with its corresponding value without changing the program's behavior
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is NOT a benefit of using pure functions?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Easier to test
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
More predictable behavior
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Easier to reason about
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Improved performance in all cases
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is the output of this pure function?
|
||||
|
||||
```javascript
|
||||
const add = (a, b) => a + b;
|
||||
console.log(add(2, 5));
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`3`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`4`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`undefined`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`7`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which statement about currying is true?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Currying always improves performance
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Curried functions are always pure functions
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Currying is only possible in functional programming languages
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Currying transforms a function with multiple arguments into a sequence of functions
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a potential side effect of the following function?
|
||||
|
||||
```javascript
|
||||
const greet = (name) => {
|
||||
console.log(`Hello, ${name}!`);
|
||||
};
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
It modifies a global variable
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
It changes the input parameter
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
It returns a value
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
It interacts with the console (I/O operation)
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
In functional programming, what is function composition?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Writing functions with multiple arguments
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Declaring functions inside other functions
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Using arrow function syntax
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Combining two or more functions to create a new function
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is an example of a pure function?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
```javascript
|
||||
const random = () => Math.random();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
```javascript
|
||||
const log = (x) => console.log(x);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
```javascript
|
||||
let count = 0;
|
||||
const increment = () => ++count;
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
```javascript
|
||||
const double = (x) => x * 2;
|
||||
```
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is the primary goal of currying?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
To improve code readability
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
To create functions with fewer arguments
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
To eliminate the need for higher-order functions
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
To enable partial application of functions
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which statement about side effects is FALSE?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Side effects make code harder to test
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Modifying a global variable is a side effect
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Reading from a database can be considered a side effect
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Pure functions can have side effects
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is the result of currying the following function?
|
||||
|
||||
```javascript
|
||||
const add = (a, b, c) => a + b + c;
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
```javascript
|
||||
const curried = (a, b, c) => a() + b() + c();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
```javascript
|
||||
const curried = a => (b, c) => a + b + c;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
```javascript
|
||||
const curried = (a, b) => c => a + b + c;
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
```javascript
|
||||
const curried = a => b => c => a + b + c;
|
||||
```
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is NOT a side effect?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Modifying the DOM
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Sending an HTTP request
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Changing the value of a global variable
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Creating a new object and returning it
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a higher-order function?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
A function that takes longer to execute
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
A function with more than three arguments
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
A function that uses advanced JavaScript features
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
A function that returns another function
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is a key principle of functional programming?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Modifying global variables frequently
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Using mutable data structures extensively
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Emphasizing object-oriented inheritance
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Avoiding side effects and using immutable data
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is the main advantage of using pure functions?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
They always execute faster than impure functions
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
They can access and modify global state easily
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
They can perform I/O operations more efficiently
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
They are easier to test and reason about
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
In the context of functional programming, what does "immutability" mean?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Variables can be declared but not assigned
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Functions cannot be modified at runtime
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Objects cannot have methods
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Data cannot be changed after it's created
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user