Skip to content

Instantly share code, notes, and snippets.

@mijimoco
Created January 14, 2017 05:58
Show Gist options
  • Save mijimoco/0eca8719f046bfb9b4aa44462be40f24 to your computer and use it in GitHub Desktop.
Save mijimoco/0eca8719f046bfb9b4aa44462be40f24 to your computer and use it in GitHub Desktop.
Return Largetst Numbers in Array
function largestOfFour(arr) {
// You can do this!
var newArray = [0,0,0,0];
var largest = 0;
for (i=0; i < 4; i++) {
for (j=0; j < 4; ++j) {
if (arr[i][j] > newArray[i]) {
newArray[i] = arr[i][j];
}
}
}
console.log(newArray);
return newArray;
}
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