Created
May 25, 2017 19:20
-
-
Save rodpoblete/7ec1139d7ee7f85beb6e532678b5985a to your computer and use it in GitHub Desktop.
Encontrar valores maximos de array de arrays FCC [247]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function largestOfFour(arr) { | |
var finalArray = []; | |
for(i = 0; i < arr.length; i++) { // itera el array padre | |
var max = -Infinity; | |
for(j = 0; j < arr[i].length; j++) { // itera sobre cad sub array | |
if(arr[i][j] > max) { // compara cada elemento sucesivo del subarray con la variable max | |
max = arr[i][j]; // si es mayor entra el if y updatea max | |
} | |
} | |
finalArray.push(max); // empuja cada valor de max despues de los loops al array nuevo declarado vacio. | |
} | |
return finalArray; // [5, 27, 39, 1001] | |
} | |
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]], ""); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment