Nodejs Array Sort sort()

Here you can find the source of sort()

Method Source Code

Array.prototype.sort = function(){
   var a = this;/*from www  .  j ava 2s.  c o  m*/
   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);
   }
}

Related

  1. sortByNumber()
    Array.prototype.sortByNumber = function() {
     return this.sort(function(a, b) { return a - b; }); 
    
  2. sortDescending()
    function getLargestPalindrome() {
      products = fillMultiples().sortDescending();
      for (i = 0; i < products.length; i++) {
        if (products[i].toString().isPalindrome()) {
          return products[i];
    function fillMultiples() {
    ...
    
  3. sortNumber(a)
    Array.prototype.sortNumber = function(a) {
      if (a == true) {
        return this.sort(function(d, c) {
          return d - c
        }).reverse()
      } else {
        return this.sort(function(d, c) {
          return d - c
        })
    ...
    
  4. sortObject(field)
    Array.prototype.sortObject = function(field) {
      if (typeof this[0][field] === 'undefined') return this;
      var len = this.length,
        i,
        j,
        flag,
        next,
        temp;
      for (i = 1; i < len; i++) {
    ...
    
  5. 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;
        })
    };
    ...
    
  6. 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;
    ...
    
  7. 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;
    ...
    
  8. 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;
    ...
    
  9. ascendSortascendSort()
    'use strict'
    Array.prototype.ascendSort = function ascendSort() {
        return this.sort(function(a, b){
            return a > b ? 1 : a < b ? -1 : 0;
        });
    };