I am new in Javascript.
function find_lowest_and_greatest(number) {
const lowest = number.sort((a, b) => a - b); // [1, 2, 3, 4, 5]
const greatest = number.sort((a, b) => b - a); // [5, 4, 3, 2, 1]
// after ^ line execute lowest value replace with greatest...But why? so lowest = [5, 4, 3, 2, 1]
return [lowest[0] , greatest[0]]
}
console.log(find_lowest_and_greatest([4, 5, 3, 1, 2])); // [5 , 5]
// expected > [1,5]
I expected result will be [1,5] But got [5,5]