Return largest Numbers in Arrays (Find out the maximum number of multiple arrays)
- Requirements
- The large array contains 4 decimal groups, each of which finds the maximum value in each decimal group, and then concatenates them together to form a new array.
- Ideas
- Use the For loop to iterate through the algebraic groups and
arr[i]
access each element of the array in a way.
- In the first layer for loop, define the variable temp as the first element of the subarray. Assigns the maximum value of the Subarray to temp in the second for loop, and then assigns the maximum value of the subarray to the corresponding element of the large array at the end of a layer of loops
- Code
1 functionLargestoffour (arr) {2 //please write down your code here.3 for(varI =0;i<arr.length;i++){4 vartemp = arr[i][0];5 for(varJ =1;j<arr[i].length;j++){6 if(Temp <Arr[i][j]) {7temp =Arr[i][j];8 }9 }TenArr[i] =temp; One } A - returnarr; - } the -Largestoffour ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
- RELATED LINKS
-
- Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
Return largest Numbers in Arrays-freecodecamp algorithm topic