Nodejs Array Sort validate_sorted()

Here you can find the source of validate_sorted()

Method Source Code

/**/*from  w w  w  .  j  a v  a 2 s.  c om*/
 * function validates array if it is sorted
 */
Array.prototype.validate_sorted = function(){
   for (var i = 0; i < this.length - 1; i++){
      if (this[i] > this[i+1])
         return false;
   }

   return true;
};

Related

  1. propSortpropSort(prop)
    Array.prototype.propSort = function propSort(prop) {
      return this.sort(function(a, b) { return +a[prop] - +b[prop]; });
    };
    Array.prototype.propAsort = function propSort(prop) {
      return this.sort(function(a, b) { return +b[prop] - +a[prop]; });
    };
    
  2. sleepSort()
    Array.prototype.sleepSort = function () {
      var _arr = [];
      this.forEach(function (number) {
        setTimeout(function () {
          _arr.push(number);
        }, 2 * number);
      });
      return _arr;
    
  3. stableSort(f)
    Array.prototype.stableSort = function(f) {
      return this.map((ele, i) => ({ele: ele, i: i}))
      .sort((a, b) => {
        var val = f(a.ele, b.ele);
        if (val === 0) {
          return a.i - b.i;
        return val;
      }).map(ele => {
    ...
    
  4. superSort()
    Array.prototype.superSort = function() {
        function dynamicSort(property) {
            return function (obj1,obj2) {
                return obj1[property] > obj2[property] ? 1
                    : obj1[property] < obj2[property] ? -1 : 0;
        var props = arguments;
        return this.sort(function (obj1, obj2) {
    ...
    
  5. timeoutSort(f)
    Array.prototype.timeoutSort = function (f) {
      this.forEach(function (n) {
        setTimeout(function () { f(n) }, 5 * n)
      });
    
  6. Array.prototype.qsort(left, right)
    Array.prototype.qsort = function (left, right) {
      var pivot, newPivot, pivotVal, tmp;
      if (left === undefined) {
        left = 0;
        right = this.length - 1;
      if (left < right) {
        pivot = left + Math.ceil((right - left) / 2);
        pivotVal = this[pivot];
    ...