Forked from anonymous/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20%2F%2F%20You%20can%20do%20this!%0A%20%20%0A%20%20var%20array%20%3D%20%5B%5D%3B%0A%20%20var%20i%20%3D%200%3B%0A%20%20var%20j%20%3D%200%3B%0A%20%20var%20x%20%
Created
November 18, 2015 00:50
-
-
Save rjmccallumbigl/c0ba1cbd98556941a5ff to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/rjmccallumbigl 's solution for Bonfire: Return Largest Numbers in Arrays
This file contains hidden or 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: @rjmccallumbigl | |
// 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%20%0A%20%20var%20array%20%3D%20%5B%5D%3B%0A%20%20var%20i%20%3D%200%3B%0A%20%20var%20j%20%3D%200%3B%0A%20%20var%20x%20%3D%200%3B%0A%20%20var%20y%20%3D%200%3B%0A%20%20%0A%20%20%2F%2Freturn%20arr%3B%0A%20%20%0A%20%20for%20(i%20%3D%200%3B%20i%20%3C%204%3B%20i%2B%2B)%7B%0A%20%20%20%20%0A%20%20%20%20x%20%3D%200%3B%0A%20%20%20%20%0A%20%20%20%20for%20(j%20%3D%200%3B%20j%20%3C%204%3B%20j%2B%2B)%7B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20if%20(arr%5Bi%5D%5Bj%5D%20%3E%20x)%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20x%20%3D%20arr%5Bi%5D%5Bj%5D%3B%20%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2Freturn%20x%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20array%5Bi%5D%20%3D%20x%3B%0A%20%20%20%20%20%20%2F%2Fx%20%3D%200%3B%0A%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%7D%0A%0A%20%20return%20array%3B%0A%7D%0A%0AlargestOfFour(%5B%5B13%2C%2027%2C%2018%2C%2026%5D%2C%20%5B4%2C%205%2C%201%2C%203%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! | |
var array = []; | |
var i = 0; | |
var j = 0; | |
var x = 0; | |
var y = 0; | |
//return arr; | |
for (i = 0; i < 4; i++){ | |
x = 0; | |
for (j = 0; j < 4; j++){ | |
if (arr[i][j] > x){ | |
x = arr[i][j]; | |
//return x; | |
} | |
array[i] = x; | |
//x = 0; | |
} | |
} | |
return array; | |
} | |
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [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