Last active
April 4, 2016 23:00
-
-
Save mmloveaa/e5f4d1e4d35f5eb97a2ea36d4a811025 to your computer and use it in GitHub Desktop.
4-4 Freecodecamp Q5
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
| Return Largest Numbers in Arrays | |
| Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays. | |
| Remember, you can iterate through an array with a simple for loop, and access each member with array syntax arr[i]. | |
| Remember to use Read-Search-Ask if you get stuck. Write your own code. | |
| function largestOfFour(arr) { | |
| for(var i=0 ; i < arr.length; i++) { | |
| arr[i].sort(function(a,b) { | |
| return b-a; | |
| }); | |
| } | |
| //console.log("arr: ", arr) | |
| var arr1 = []; | |
| for (j=0; j<arr.length; j++){ | |
| arr1.push(arr[j][0]); | |
| } | |
| return arr1; | |
| } | |
| 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