-
-
Save anonymous/c136f657687a0f54c763 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbagia 's solution for Bonfire: Return Largest Numbers in Arrays
This file contains 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
// Bonfire: Return Largest Numbers in Arrays | |
// Author: @dbagia | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20%2F%2F%20You%20can%20do%20this!%0A%20%20arr%20%3D%20arr.map(function(subarr)%7B%0A%20%20%20%20return%20subarr.sort(function(a%2Cb)%7B%0A%20%20%20%20%20%20return%20b%20-%20a%3B%0A%20%20%20%20%7D)%5B0%5D%3B%0A%20%20%7D)%3B%0A%20%20return%20arr%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) { | |
// You can do this! | |
arr = arr.map(function(subarr){ | |
return subarr.sort(function(a,b){ | |
return b - a; | |
})[0]; | |
}); | |
return arr; | |
} | |
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