Last active
June 27, 2017 10:06
-
-
Save AyoAlfonso/855306083077dfe816ec8d61f0d7310c to your computer and use it in GitHub Desktop.
Finding The Highest Numbers in A Double Deep Array
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
function largestOfFour(arr) { | |
var largestNumber = [0,0,0,0]; | |
for(var arrayIndex = 0; arrayIndex < arr.length; arrayIndex++) { | |
for(var subArrayIndex = 0; subArrayIndex < arr[arrayIndex].length; subArrayIndex++) { | |
if(arr[arrayIndex][subArrayIndex] > largestNumber[arrayIndex]) { | |
largestNumber[arrayIndex] = arr[arrayIndex][subArrayIndex]; | |
} | |
} | |
} | |
return largestNumber; | |
} | |
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