Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2015 03:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/ccbac2702f8b5749d462 to your computer and use it in GitHub Desktop.
Save anonymous/ccbac2702f8b5749d462 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbess1 's solution for Bonfire: Return Largest Numbers in Arrays
// Bonfire: Return Largest Numbers in Arrays
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
var numbers = [];
for(var i = 0; i < arr.length; i++){ //for iterating through the large array
var biggestNumber = 0;
for(var j = 0; j < arr[i].length; j++){ //for iterating through the sub-arrays
if(arr[i][j] > biggestNumber){
biggestNumber = arr[i][j];
}
}
numbers[i] = biggestNumber;
}
return numbers;
}
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