This may sound like an odd one, but I’ve completed this unit and I was very happy to have done so at the first time of trying, my thought process was to loop through the sub arrays and sort the elements into ascending order, from there just pop off the end of the array and bosh, sorted.
However, after I’ve finished the until I looked at the examples in the get a hint section and now I’m wondering if I’ve missed the point of this unit completely or have I just completed this unit the way that I currently know how to solve a problem in my mind?
A developer once told me, “it doesn’t matter as long as you get it to work, then you can go about making it better” I assume that might apply here but was hoping to get some feedback on the style of the completed outcome.
Your code so far
function ascendingOrder(a, b){
return a - b;
}
function largestOfFour(arr) {
let newArr = [];
for(let i = 0; i < arr.length; i++){
newArr.push(arr[i].sort(ascendingOrder).pop())
}
return newArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: