-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlargest_of_4_arrays.js
28 lines (23 loc) · 1.13 KB
/
largest_of_4_arrays.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function largestOfFour(arr) {
var array_of_large_num_in_each_subarray = [];
arr.forEach(function(subarray,index){
console.log("subarray " +subarray);
var temp = 0;
subarray.forEach(function(item,index){
console.log("ITEM--->" + item);
if(item > temp){
temp = item;
}
});
array_of_large_num_in_each_subarray.push(temp);
});
return array_of_large_num_in_each_subarray;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
/*
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].
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return an array.
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return [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].
*/