Check if an array is descending, ascending or not sorted?

后端 未结 7 1765
不思量自难忘°
不思量自难忘° 2021-01-18 09:01

I\'m just beginning with programming using javascript and I need to practice some questions to get EXP with the logic of code build. I got this question for homework but I c

7条回答
  •  孤城傲影
    2021-01-18 09:40

    function findOrder(array) {
        var asc = true;
        var desc = true;
        if(array.length < 2){
            return 'array is too small'
        }
        for(var i=1, len=array.length;iarray[i-1]){
                desc = false;
            //if current element is smaller than previous array is not ascending
            }else if(array[i]

提交回复
热议问题