Forked from anonymous/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20%2F%2F%20You%20can%20do%20this!%0A%20%20%0A%20%20var%20results%20%3D%20%5B%5D%3B%0A%20%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%3B%20i%
Last active
November 20, 2015 06:07
-
-
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
This file contains 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
// 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