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

后端 未结 7 1704
不思量自难忘°
不思量自难忘° 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:59

    function isAscending(arr = []) {
      for (let i = 0; i < arr.length; i++) {
        if (arr[i + 1] <= arr[i]) {
          return false;
        }
      }
      return true;
    }
    

提交回复
热议问题