Hi, coders!
I need help to understand, is my code good enough? and if not, what is it’s sensible place? why it’s bad from practice point of view?
Your code so far
function largestOfFour(arr) {
// You can do this!
var newArr =[];
var final;
var pushed;
var separatedArr;
var sorted;
for (var i = 0; i < arr.length; i++){
separatedArr = arr[i].sort(function (a, b) {
if (b > a){return b;}
});
sorted = separatedArr.splice(0, 1);
pushed = newArr.push(sorted);
final = newArr.reduce(function(flat, current) {
return flat.concat(current);
}, []);
console.log(final);
}
return final;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: