Created
July 12, 2015 20:34
-
-
Save svahora/7aa544b2649d9b21e312 to your computer and use it in GitHub Desktop.
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
function largestOfFour(arr) { | |
var largest = 0; | |
var newArr = []; | |
for(x=0; x<arr.length; x++) { | |
for(y=0; y<arr[x].length; y++){ console.log(arr[x][y]); | |
if(arr[x][y]>largest) { | |
largest = arr[x][y]; | |
} | |
} newArr.push(largest); | |
} return newArr; | |
} | |
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); |
function largestOfFour(arr) {
var newArray = [];
for(i=0; i<arr.length; i++) {
newArray.push(arr[i].sort(function(a,b) { return a < b; })[0]);
}
return newArray;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my answer may be able to understand more easier than top. but not the best one.
function largest(arr){
var largest = 0;
for(var i in arr){
if(arr[i] >= largest) largest = arr[i];
}
return largest;
}
function largestOfFour(arr) {
var newarr= new Array;
for (var i in arr){
newarr[i] = largest(arr[i]);
}
return newarr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);