Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/e19810b23ec893ed8ce4 to your computer and use it in GitHub Desktop.
Save anonymous/e19810b23ec893ed8ce4 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/srkama 's solution for Bonfire: Return Largest Numbers in Arrays
// Bonfire: Return Largest Numbers in Arrays
// Author: @srkama
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20maxArray%20%3D%20new%20Array(arr.length)%3B%0A%20%20for(i%3D0%3Bi%3Carr.length%3Bi%2B%2B)%7B%0A%20%20%20%20maxArray%5Bi%5D%3DMath.max.apply(null%2Carr%5Bi%5D)%3B%0A%20%20%7D%0A%20%20%2F%2F%20You%20can%20do%20this!%0A%20%20return%20maxArray%3B%0A%7D%0A%0AlargestOfFour(%5B%5B4%2C%205%2C%201%2C%203%5D%2C%20%5B13%2C%2027%2C%2018%2C%2026%5D%2C%20%5B32%2C%2035%2C%2037%2C%2039%5D%2C%20%5B1000%2C%201001%2C%20857%2C%201%5D%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
maxArray = new Array(arr.length);
for(i=0;i<arr.length;i++){
maxArray[i]=Math.max.apply(null,arr[i]);
}
// You can do this!
return maxArray;
}
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