Skip to content

Instantly share code, notes, and snippets.

@efarioli
Created November 26, 2016 23:04
Show Gist options
  • Save efarioli/de1da3c5b07861c600ce5529476ae560 to your computer and use it in GitHub Desktop.
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.
//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