Check if an array is sorted, return true or false

前端 未结 13 1974
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 06:03

I am writing an easy program the just returns true if an array is sorted else false and I keep getting an exception in eclipse and I just can\'t figure out why. I was wonder

13条回答
  •  天命终不由人
    2020-11-30 06:29

    Array.prototype.every

    The every() method tests whether all elements in the array pass the test implemented by the provided function.

    arr.every(function (a, b) {
      return a > b;
    });
    
    var arr = [1,2,3] // true
    
    var arr = [3,2,1] // false
    

提交回复
热议问题