Created
December 20, 2016 18:12
-
-
Save bflannery/49e4d7ae3d607ddc24c62dc720ff7369 to your computer and use it in GitHub Desktop.
Return Largest Number In An Array
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
// Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain 4 sub-arrays. | |
function largestOfFour(arr) { | |
let largestNumber = [0,0,0,0]; | |
for(var i=0; i < arr.length; i++) { | |
for(var j=0; j < arr[i].length; j++) { | |
if(arr[i][j] > largestNumber[i]) { | |
largestNumber[i] = arr[i][j]; | |
} | |
} | |
} | |
return largestNumber; | |
} | |
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])); | |
console.log(largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])); | |
console.log(largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment