Created
December 3, 2015 15:01
-
-
Save manojrammurthy/ee698221708c58d23166 to your computer and use it in GitHub Desktop.
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
| function largestOfFour(arr) { | |
| // You can do this! | |
| var arr1=[]; | |
| for(var i=0; i<arr.length; i++){ | |
| var subArr=arr[i]; | |
| var largest= Math.max.apply(Math,subArr); | |
| arr1.push(largest); | |
| } | |
| return arr1; | |
| } | |
| largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
one can change their for loop like this as well
for(var i=0; i<arr.length; i++){
var largest= Math.max.apply(null,subArr);
arr1.push(largest);
}
or
for(var i=0; i<arr.length; i++){
var largest= Math.max.apply(Undefined,subArr);
arr1.push(largest);
}
or
for(var i=0; i<arr.length; i++){
var largest= Math.max.apply(undefined,subArr);
arr1.push(largest);
}