Besides sorting the array arr, the array brr will be also
rearranged as the same order of arr.
962702
public static <T extends Comparable<? super T>>  void sort(T[] arr, int[] brr) {
        sort(arr, brr, arr.length);
    }
374532
function (ary) {
  var shuffled = [];
  ary.reduce(function (acc, v) {
    var r = range(0, acc);
    shuffled[acc] = shuffled[r];
    shuffled[r] = v;
    return acc + 1;
  }, 0);
  return shuffled;
}
336737
public void permute(final int[] arr) {
    checkArgument(arr.length == sources.length);
    final int[] tmp = new int[arr.length];
    for (int i = 0; i < tmp.length; ++i) {
      tmp[i] = arr[sources[i]];
    }
    System.arraycopy(tmp, 0, arr, 0, arr.length);
  }
492037
function ( a )
	{
		if ( a.length != this.s.dt.aoColumns.length )
		{
			this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+
				"match known number of columns. Skipping." );
			return;
		}

		for ( var i=0, iLen=a.length ; i<iLen ; i++ )
		{
			var currIndex = $.inArray( i, a );
			if ( i != currIndex )
			{
				/* Reorder our switching array */
				fnArraySwitch( a, currIndex, i );

				/* Do the column reorder in the table */
				this.s.dt.oInstance.fnColReorder( currIndex, i );
			}
		}

		/* When scrolling we need to recalculate the column sizes to allow for the shift */
		if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
		{
			this.s.dt.oInstance.fnAdjustColumnSizing( false );
		}

		/* Save the state */
		this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );

		this._fnSetColumnIndexes();
		
		if ( this.s.reorderCallback !== null )
		{
			this.s.reorderCallback.call( this );
		}
	}
813598
public static <T> void swap(T[] arr, int a, int b) {
		if (a < 0 || a > arr.length || b < 0 || b > arr.length)
			throw new IllegalArgumentException("swap position out of bounds.");
		if (a != b) {
			T t = arr[a];
			arr[a] = arr[b];
			arr[b] = t;
		}
	}
606109
private void sort(final T[] array, int start, int end, Comparator<T> lt) {
    if (start == end)
      return;
    if ((end - start) <= 15)
      this.selectionSort(array, start, end, lt);
    else {
      final T pivot = array[start + ((end - start) / 2)];
      T tmp;
      int i = start - 1;
      int j = end;
      while (true) {
        do
          i++;
        while (lt.compare(array[i], pivot) < 0);
        do
          j--;
        while (lt.compare(pivot, array[j]) < 0);
        if (i >= j)
          break;
        tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
      }
      this.sort(array, start, i, lt);
      this.sort(array, i, end, lt);
    }
  }
109280
function order (d, arr, visited) {
  for (let i in d) {
    if (!visited[i]) {
      let obj = d[i]
      visited[i] = true
      arr = arr.concat(order(obj, [], visited))
      if (css(i)) {
        arr.push(i)
      }
    }
  }
  return arr
}
39477
function swap(arr, i1, i2) {
  const tmp = arr[i1];
  arr[i1] = arr[i2];
  arr[i2] = tmp;
}
216008
public static <T extends Comparable<? super T>> void siftUp(T[] arr, int k) {
        while (k > 1 && arr[k/2].compareTo(arr[k]) < 0) {
            swap(arr, k, k/2);
            k = k/2;
        }
    }
1347753
function selectionSort(arr) {

  /* recursion anchor: one element is always sorted */
  if (arr.length === 1) return arr;
  var minimum = Infinity;
  var index = void 0;
  for (var i in arr) {
    if (arr[i] < minimum) {
      minimum = arr[i];
      index = i; /* remember the minimum index for later removal */
    }
  }

  /* remove the minimum */
  arr.splice(index, 1);

  /* assemble result and sort recursively (could be easily done iteratively as well)*/
  return [minimum].concat(selectionSort(arr));
}
91648
function mergeSort(arr) {

  /* merges two sorted arrays into one sorted array */
  function merge(a, b) {

    /* result set */
    var c = [];

    /* as long as there are elements in the arrays to be merged */
    while (a.length > 0 || b.length > 0) {

      /* are there elements to be merged, if yes, compare them and merge */
      var n = a.length > 0 && b.length > 0 ? a[0] < b[0] ? a.shift() : b.shift() : b.length > 0 ? b.shift() : a.length > 0 ? a.shift() : null;

      /* always push the smaller one onto the result set */
      if (n !== null) {
        c.push(n);
      }
    }
    return c;
  }

  /* this mergeSort implementation cuts the array in half, wich should be fine with randomized arrays, but introduces the risk of a worst-case scenario */
  median = Math.floor(arr.length / 2);
  var part1 = arr.slice(0, median); /* for some reason it doesn't work if inserted directly in the return statement (tried so with firefox) */
  var part2 = arr.slice(median - arr.length);
  return arr.length <= 1 ? arr : merge(mergeSort(part1), /* first half */
  mergeSort(part2) /* second half */
  );
}
588364
function sortBy(array, attr) {
  assert(Array.isArray(array));
  return array.sort(function(a,b) {
    a = a[attr];
    b = b[attr];
    return (a < b) ? -1 : ((a > b) ? 1 : 0);
  });
}
81844
function arraySortByKey(data, key, reverse) {
    data.sort((a, b) => {
        const aw = a[key] !== undefined ? (
            typeof a[key] === 'function' ?
            parseInt(a[key](), 10) :
            parseInt(a[key], 10)
        ) : 0;
        const bw = b[key] !== undefined ? (
            typeof b[key] === 'function' ?
            parseInt(b[key](), 10) :
            parseInt(b[key], 10)
        ) : 0;

        if (aw === bw) {
            return 0;
        }

        return reverse !== true && aw < bw ? -1 : 1;
    });
}
1086009
public static void sort(int[] intArray) {
        int minIndex = 0;
        for(int i = 0; i < intArray.length; i++) {
            minIndex = i;
            
            for(int j = minIndex; j < intArray.length; j++) {
                if(intArray[j] < intArray[minIndex]) {
                    minIndex = j;
                }
            }
            XORSwap.swap(intArray, i, minIndex);
        }
    }
50140
public static void sort(short[] shortArray) {
        boolean swapped = true;
        
        while(swapped) {
            swapped = false;
            
            for(int i = 0; i < (shortArray.length - 1 ); i++) {
                if(shortArray[i] > shortArray[i + 1]) {
                    TrivialSwap.swap(shortArray, i, i + 1);
                    
                    swapped = true;
                }
            }            
        }
    }
1041944
function sort(array, compare) {
  var workArray = new Array(array.length);
  var chunkSize = 1;
  while (chunkSize < array.length) {
    var i = 0;
    while (i < array.length - chunkSize) {
      bottomUpMerge(array, i, chunkSize, workArray, compare);
      i += chunkSize * 2;
    }
    chunkSize *= 2;
  }
  return array;
}
921004
public static void sortDescending(long[] longArray) {
        int index = 0;
        long value = 0;
        
        for(int i = 1; i < longArray.length; i++) {
            index = i;
            value = longArray[index];
            
            while(index > 0 && value > longArray[index - 1]) {
                longArray[index] = longArray[index - 1];
                
                index--;
            }
            
            longArray[index] = value;
        }
    }