Skip to content

Instantly share code, notes, and snippets.

@waltzaround
Last active September 30, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waltzaround/c359f1c1a1bc0827f9ea to your computer and use it in GitHub Desktop.
Save waltzaround/c359f1c1a1bc0827f9ea to your computer and use it in GitHub Desktop.
function largestOfFour(arr) {
var end = []; // so we create an array called end
for(var a = 0; a < arr.length; a++){ // as we cycle through the sub-arrays that were given to us by arr...
var maximum = 0; // we create a variable called maximum
var inner = arr[a]; // we create a variable called inner.. it is equal in value to the selected arr array
for(var b = 0; b < inner.length; b++){ // as we cycle through the values in the selected array...
if (inner[b] > maximum) // if there is a higher value than what we have found...
maximum = inner[b]; // then the higher value that we found is now the highest value
}
end.push(maximum); // push the highest number out of the array
}
return end; // output the values in the end array out of the largestOfFour function
}
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