dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
103 lines
2.0 KiB
Markdown
103 lines
2.0 KiB
Markdown
---
|
|
id: a789b3483989747d63b0e427
|
|
title: Return Largest Numbers in Arrays
|
|
challengeType: 1
|
|
forumTopicId: 16042
|
|
dashedName: return-largest-numbers-in-arrays
|
|
---
|
|
|
|
# --description--
|
|
|
|
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
|
|
|
|
Remember, you can iterate through an array with a simple for loop, and access each member with array syntax `arr[i]`.
|
|
|
|
# --hints--
|
|
|
|
`largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])` should return an array.
|
|
|
|
```js
|
|
assert.isArray(
|
|
largestOfFour([
|
|
[4, 5, 1, 3],
|
|
[13, 27, 18, 26],
|
|
[32, 35, 37, 39],
|
|
[1000, 1001, 857, 1]
|
|
])
|
|
);
|
|
```
|
|
|
|
`largestOfFour([[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(
|
|
largestOfFour([
|
|
[13, 27, 18, 26],
|
|
[4, 5, 1, 3],
|
|
[32, 35, 37, 39],
|
|
[1000, 1001, 857, 1]
|
|
]),
|
|
[27, 5, 39, 1001]
|
|
);
|
|
```
|
|
|
|
`largestOfFour([[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(
|
|
largestOfFour([
|
|
[4, 9, 1, 3],
|
|
[13, 35, 18, 26],
|
|
[32, 35, 97, 39],
|
|
[1000000, 1001, 857, 1]
|
|
]),
|
|
[9, 35, 97, 1000000]
|
|
);
|
|
```
|
|
|
|
`largestOfFour([[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(
|
|
largestOfFour([
|
|
[17, 23, 25, 12],
|
|
[25, 7, 34, 48],
|
|
[4, -10, 18, 21],
|
|
[-72, -3, -17, -10]
|
|
]),
|
|
[25, 48, 21, -3]
|
|
);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function largestOfFour(arr) {
|
|
return arr;
|
|
}
|
|
|
|
largestOfFour([
|
|
[4, 5, 1, 3],
|
|
[13, 27, 18, 26],
|
|
[32, 35, 37, 39],
|
|
[1000, 1001, 857, 1]
|
|
]);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function largestOfFour(arr) {
|
|
return arr.map(subArr => Math.max.apply(null, subArr));
|
|
}
|
|
|
|
largestOfFour([
|
|
[4, 5, 1, 3],
|
|
[13, 27, 18, 26],
|
|
[32, 35, 37, 39],
|
|
[1000, 1001, 857, 1]
|
|
]);
|
|
```
|