mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(curriculum): add largest numbers lab (#61376)
Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
@@ -3262,6 +3262,12 @@
|
||||
"In these lecture videos, you will learn more about the core JavaScript fundamentals. You will learn how a string object differs from a primitive string, the <code>toString()</code> method, conventions and common practices for naming variables, linters and formatters, closures, and much more."
|
||||
]
|
||||
},
|
||||
"lab-largest-number-finder": {
|
||||
"title": "Build the Largest Number Finder",
|
||||
"intro": [
|
||||
"In this lab, you will use JavaScript fundamentals to create a function that finds the largest number in each sub-array of a given array."
|
||||
]
|
||||
},
|
||||
"lab-slice-and-splice": {
|
||||
"title": "Implement the Slice and Splice Algorithm",
|
||||
"intro": [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Build the Largest Number Finder
|
||||
block: lab-largest-number-finder
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to the Build the Largest Number Finder
|
||||
|
||||
In this lab, you will use JavaScript fundamentals to create a function that finds the largest number in each sub-array of a given array.
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Build the Largest Number Finder",
|
||||
"isUpcomingChange": false,
|
||||
"dashedName": "lab-largest-number-finder",
|
||||
"superBlock": "full-stack-developer",
|
||||
"helpCategory": "JavaScript",
|
||||
"challengeOrder": [{ "id": "a789b3483989747d63b0e427", "title": "Build the Largest Number Finder" }],
|
||||
"usesMultifileEditor": true,
|
||||
"blockType": "lab",
|
||||
"blockLayout": "link"
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
---
|
||||
id: a789b3483989747d63b0e427
|
||||
title: Build the Largest Number Finder
|
||||
challengeType: 26
|
||||
dashedName: build-the-largest-number-finder
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this lab, you will build a function that returns an array consisting of the largest number from each provided sub-array.
|
||||
|
||||
Remember, you can iterate through an array with a simple `for` loop, and access each member with array syntax `arr[i]`.
|
||||
|
||||
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should create a function `largestOfAll` that takes an array of arrays as an argument.
|
||||
2. The function should return an array containing the largest number from each sub-array.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should create a function named `largestOfAll`.
|
||||
|
||||
```js
|
||||
assert.isFunction(largestOfAll);
|
||||
```
|
||||
|
||||
`largestOfAll` should take a single parameter.
|
||||
|
||||
```js
|
||||
assert.lengthOf(largestOfAll, 1);
|
||||
```
|
||||
|
||||
`largestOfAll([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])` should return an array.
|
||||
|
||||
```js
|
||||
assert.isArray(
|
||||
largestOfAll([
|
||||
[4, 5, 1, 3],
|
||||
[13, 27, 18, 26],
|
||||
[32, 35, 37, 39],
|
||||
[1000, 1001, 857, 1]
|
||||
])
|
||||
);
|
||||
```
|
||||
|
||||
`largestOfAll([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])` should return `[27, 5, 39, 1001]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
largestOfAll([
|
||||
[13, 27, 18, 26],
|
||||
[4, 5, 1, 3],
|
||||
[32, 35, 37, 39],
|
||||
[1000, 1001, 857, 1]
|
||||
]),
|
||||
[27, 5, 39, 1001]
|
||||
);
|
||||
```
|
||||
|
||||
`largestOfAll([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])` should return `[9, 35, 97, 1000000]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
largestOfAll([
|
||||
[4, 9, 1, 3],
|
||||
[13, 35, 18, 26],
|
||||
[32, 35, 97, 39],
|
||||
[1000000, 1001, 857, 1]
|
||||
]),
|
||||
[9, 35, 97, 1000000]
|
||||
);
|
||||
```
|
||||
|
||||
`largestOfAll([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])` should return `[25, 48, 21, -3]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
largestOfAll([
|
||||
[17, 23, 25, 12],
|
||||
[25, 7, 34, 48],
|
||||
[4, -10, 18, 21],
|
||||
[-72, -3, -17, -10]
|
||||
]),
|
||||
[25, 48, 21, -3]
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function largestOfAll(arr) {
|
||||
return arr.map(subArr => Math.max.apply(null, subArr));
|
||||
}
|
||||
|
||||
largestOfAll([
|
||||
[4, 5, 1, 3],
|
||||
[13, 27, 18, 26],
|
||||
[32, 35, 37, 39],
|
||||
[1000, 1001, 857, 1]
|
||||
]);
|
||||
```
|
||||
@@ -721,6 +721,9 @@
|
||||
{
|
||||
"dashedName": "lecture-understanding-core-javascript-fundamentals"
|
||||
},
|
||||
{
|
||||
"dashedName": "lab-largest-number-finder"
|
||||
},
|
||||
{
|
||||
"dashedName": "lab-slice-and-splice"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user