function isSortedAndHow(array) {
let array_copy=array.slice(0,array.length);
let ascending_arr=array.sort((a,b)=>{return a-b});
let descending_arr=array.sort((a,b)=>{return b-a});
//for checking array equality
function element_check(arr1,arr2){
return arr1.every((a1,a2)=>{a1===arr2[a2]})
}
if(element_check(array,ascending_arr)){
return "yes,ascending order";
}
else if(element_check(array,descending_arr)){
return "yes,descending order";
}
else{
return "no";
}
}
I'm trying to accept an array, check if it is sorted in any order and return output. However,the code is returning no all the time.