Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 02:41
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 piqueen314/6689c87dd709e7e958a6 to your computer and use it in GitHub Desktop.
Save piqueen314/6689c87dd709e7e958a6 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.
// Bonfire: Return Largest Numbers in Arrays
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
// You can do this!
var newArr=[];
for(var i=0; i<arr.length; i++){
var max =0;
for(var j=0; j< 4; j++){
if(arr[i][j]>max){
max=arr[i][j];
newArr[i]=max;
}
}
}
return newArr;
}
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