Nodejs Array Sort ascendSortascendSort()

Here you can find the source of ascendSortascendSort()

Method Source Code

'use strict'//from  w w  w . j  a va 2  s .  co  m

Array.prototype.ascendSort = function ascendSort() {
    return this.sort(function(a, b){
        return a > b ? 1 : a < b ? -1 : 0;
    });
};

Related

  1. sort_text(direction, index)
    Array.prototype.sort_text = function(direction, index) {
        direction = direction === undefined ? 'asc' : direction;
        direction = direction === 'asc' ? 1 : -1;
        this.sort(function(a, b) {
            if (a[index] < b[index]) return -direction;
            if (a[index] > b[index]) return direction;
            return 0;
        })
    };
    ...
    
  2. sort()
    Array.prototype.sort = function(){
      var a = this;
      for(var i = 0;i<a.length-1;i++){
        var t = i;
        for(var j = i+1;j<a.length;j++)
          if(a[t]>a[j])
            t = j;
        if(t!=i)
          this.swap(i,t);
    ...
    
  3. alphanumSort( caseInsensitive )
    Array.prototype.alphanumSort = function( caseInsensitive ) {
      for ( var z = 0, t; t = this[z]; z++ ) {
        this[z] = [];
        var x = 0, y = -1, n = 0, i, j;
        while (i = ( j = t.charAt( x++ ) ).charCodeAt( 0 ) ) {
          var m = ( i == 46 || ( i >=48 && i <= 57 ) );
          if ( m !== n ) {
            this[z][++y] = "";
            n = m;
    ...
    
  4. alphanumSort(caseInsensitive)
    Array.prototype.alphanumSort = function(caseInsensitive) {
      for (var z = 0, t; t = this[z]; z++) {
        this[z] = [];
        var x = 0, y = -1, n = 0, i, j;
        while (i = (j = t.charAt(x++)).charCodeAt(0)) {
          var m = (i == 46 || (i >=48 && i <= 57));
          if (m !== n) {
            this[z][++y] = "";
            n = m;
    ...
    
  5. alphanumSort(caseInsensitive)
    Array.prototype.alphanumSort = function(caseInsensitive) {
      for (var z = 0, t; t = this[z]; z++) {
        this[z] = new Array();
        var x = 0, y = -1, n = 0, i, j;
        while (i = (j = t.charAt(x++)).charCodeAt(0)) {
          var m = (i == 46 || (i >=48 && i <= 57));
          if (m !== n) {
            this[z][++y] = "";
            n = m;
    ...
    
  6. asort(key)
    function xsort(sqs,col,order){
        sqs.sort(function(a,b){
            return((a[col]-b[col])*order);
        });
        return(sqs);
    Array.prototype.asort = function(key) {
        this.sort(function(a, b) {
            return (a[key] > b[key]) ? 1 : -1;
    ...
    
  7. countingSort()
    Array.prototype.countingSort = function() {
      var maxDigit = this[0];
      for(var i = 1; i < this.length; i++) {
        if(this[i] > maxDigit) {
          maxDigit = this[i];
      var bucket = new Array(maxDigit + 1);
      for(var i = 0; i < this.length; i++) {
    ...
    
  8. descendSortascendSort()
    Array.prototype.descendSort = function ascendSort() {
        return this.sort(function(a, b){
            return a < b ? 1 : a > b ? -1 : 0;
        });
    };
    
  9. humanSort()
    Array.prototype.humanSort = function() {
      return this.sort(function(a, b) {
        aa = a.split(/(\d+)/);
        bb = b.split(/(\d+)/);
        for(var x = 0; x < Math.max(aa.length, bb.length); x++) {
          if(aa[x] != bb[x]) {
            var cmp1 = (isNaN(parseInt(aa[x],10)))? aa[x] : parseInt(aa[x],10);
            var cmp2 = (isNaN(parseInt(bb[x],10)))? bb[x] : parseInt(bb[x],10);
            if(cmp1 == undefined || cmp2 == undefined)
    ...