Created
November 26, 2016 23:04
-
-
Save efarioli/de1da3c5b07861c600ce5529476ae560 to your computer and use it in GitHub Desktop.
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-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
//javascript | |
function largestOfOne(arr) { | |
var largest = 0; | |
console.log(arr.length); | |
for (i = 0; i < arr.length; i++) { | |
console.log(i); | |
if (largest < arr[i]) { | |
largest = arr[i]; | |
} | |
} | |
console.log(largest); | |
return largest; | |
} | |
largestOfOne([0, 15, 32, 18]); | |
function largestOfFour(arr) { | |
// You can do this! | |
//console.log(arr[0]+"allala"); | |
var arrResult=[]; | |
for (x = 0; x < arr.length; x++) { | |
arrResult.push(largestOfOne(arr[x])); | |
console.log(largestOfOne(arr[x])+" "+x); | |
} | |
return arrResult; | |
} | |
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