Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c07abe

Browse filesBrowse files
committed
[ADD] largestNumber added
1 parent a2bfbe1 commit 6c07abe
Copy full SHA for 6c07abe

File tree

Expand file treeCollapse file tree

2 files changed

+25
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-0
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,19 @@ filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3) should return
256256

257257
The filteredArray function should utilize a for loop
258258
```
259+
260+
261+
## Largest Numbers in Arrays
262+
263+
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
264+
265+
266+
```javascript
267+
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return an array.
268+
269+
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return [27, 5, 39, 1001].
270+
271+
largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]) should return [9, 35, 97, 1000000].
272+
273+
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]) should return [25, 48, 21, -3].
274+
```

‎src/largestNumber.js

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function largestOfFour(arr) {
2+
const largestArray = [];
3+
for(let i in arr){
4+
largestArray.push(Math.max(...arr[i]));
5+
}
6+
return largestArray;
7+
};
8+
9+
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.