Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Created September 7, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgresalfi/26604a0c5dcaefcf9eeb47115f32bae7 to your computer and use it in GitHub Desktop.
Save jgresalfi/26604a0c5dcaefcf9eeb47115f32bae7 to your computer and use it in GitHub Desktop.
Function to iterate through nested arrays and find largest values in each.
function largestOfFour(arr) {
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
arr[i] = Math.max(...arr[i]);
}
}
return arr;
}
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