Created
December 9, 2015 20:29
-
-
Save anonymous/193a3c122612787e88b6 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/goteamtim 's solution for Bonfire: Return Largest Numbers in Arrays
This file contains hidden or 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: @goteamtim | |
| // 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) { | |
| //initialize the array to return from the function | |
| var arrayToReturn = []; | |
| //loop through main array | |
| for (var i = 0; i < arr.length; i++) { | |
| //set the largest number to 0 | |
| var largestNumInArray = 0; | |
| var currentArray = arr[i]; | |
| //loop through the contained array | |
| for (var j = 0; j < currentArray.length; j++) { | |
| if (largestNumInArray < currentArray[j]) { | |
| largestNumInArray = currentArray[j]; | |
| }; | |
| }; | |
| //Build an array to return | |
| arrayToReturn[i] = largestNumInArray; | |
| }; | |
| return arrayToReturn; | |
| } | |
| 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