lib/radix-sort.js
function sort(array, radix) {
  if (array.length === 0) {
    return array;
  }

  radix = radix || 10;

  // Determine minimum and maximum values
  var minValue = array[0];
  var maxValue = array[0];
  for (var i = 1; i < array.length; i++) {
    if (array[i] < minValue) {
      minValue = array[i];
    } else if (array[i] > maxValue) {
      maxValue = array[i];
    }
  }

  // Perform counting sort on each exponent/digit, starting at the least
  // significant digit
  var exponent = 1;
  while ((maxValue - minValue) / exponent >= 1) {
    array = countingSortByDigit(array, radix, exponent, minValue);

    exponent *= radix;
  }

  return array;
}
function sort(array, radix) {
  if (array.length === 0) {
    return array;
  }

  radix = radix || 10;

  // Determine minimum and maximum values
  var minValue = array[0];
  var maxValue = array[0];
  for (var i = 1; i < array.length; i++) {
    if (array[i] < minValue) {
      minValue = array[i];
    } else if (array[i] > maxValue) {
      maxValue = array[i];
    }
  }

  // Perform counting sort on each exponent/digit, starting at the least
  // significant digit
  var exponent = 1;
  while ((maxValue - minValue) / exponent >= 1) {
    array = countingSortByDigit(array, radix, exponent, minValue);

    exponent *= radix;
  }

  return array;
}
function sort ( array , radix ) { if ( array . length === 0 ) { return array ; } radix = radix || 10 ; // Determine minimum and maximum values var minValue = array [ 0 ] ; var maxValue = array [ 0 ] ; for ( var i = 1 ; i < array . length ; i ++ ) { if ( array [ i ] < minValue ) { minValue = array [ i ] ; } else if ( array [ i ] > maxValue ) { maxValue = array [ i ] ; } } // Perform counting sort on each exponent/digit, starting at the least // significant digit var exponent = 1 ; while ( ( maxValue - minValue ) / exponent >= 1 ) { array = countingSortByDigit ( array , radix , exponent , minValue ) ; exponent *= radix ; } return array ; }
Sorts an array using radix sort.
@param {Array} array The array to sort.
@param {number} [radix=10] The base/radix to use.
@returns The sorted array.
Sorts an array using radix sort .