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

后端 未结 7 1627
不思量自难忘°
不思量自难忘° 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;
    }
    
    0 讨论(0)
提交回复
热议问题