Reputation: 79
Why do ascending and descending arrays give the same output? Anyone can solve this?
function isSortedAndHow(arr) {
let asc = arr.sort((a, b) => a - b); // Ascending order , yes
let dsc = arr.sort((a, b) => b - a); // descending array, yes
if (arr == asc) {
console.log("Ascending , Yes");
} else if (arr == dsc) {
console.log("Descending , Yes");
} else {
console.log("No");
}
}
isSortedAndHow([25,20,15,30,35]);
Upvotes: 0
Views: 19