Skip to content

Instantly share code, notes, and snippets.

  • Save twhite96/83680dba59fcf7430e5e to your computer and use it in GitHub Desktop.
Save twhite96/83680dba59fcf7430e5e to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/twhite96 's solution for Bonfire: Return Largest Numbers in Arrays
// Bonfire: Return Largest Numbers in Arrays
// Author: @twhite96
function largestOfFour(arr) {
// You can do this!
//Need a place to store the solution
var results = [];
//this loop iterates through the main array: remember, you can have nested loops
for (var i = 0; i < arr.length; i++) {
//variable to hold the largest number
var largeNum = 0;
//this loop iterates through the inner arrays and to see if the elements are bigger than the largest number
//if it is it saves the number back into the var results array
for (var n = 0; n < arr[i].length; n++) {
if (arr[i][n] > largeNum) {
largeNum = arr[i][n];
}
}
results[i] = largeNum;
}
return results;
}
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