radix Sort Algorithm

radix sort can be apply to data that can be sorted lexicographically, be they integers, words, punch cards, playing cards, or the mail. It avoids comparison by make and distribute components into buckets according to their radix. radix sorting algorithms get into common purpose as a manner to sort punched cards as early as 1923.The first memory-efficient computer algorithm was developed in 1954 at MIT by Harold H. Seward. The linear scan is closely associated to Seward's other algorithm — counting sort. computerize radix kinds had previously been dismissed as impractical because of the perceived need for variable allocation of buckets of unknown size.
/*
* Radix sorts an integer array without comparing the integers.
* It groups the integers by their digits which share the same
* significant position.
* For more information see: https://en.wikipedia.org/wiki/Radix_sort
*/
function radixSort (items, RADIX) {
  // default radix is then because we usually count to base 10
  if (RADIX === undefined || RADIX < 1) {
    RADIX = 10
  }

  var maxLength = false
  var placement = 1

  while (!maxLength) {
    maxLength = true
    var buckets = []

    for (var i = 0; i < RADIX; i++) {
      buckets.push([])
    }

    for (var j = 0; j < items.length; j++) {
      var tmp = items[j] / placement
      buckets[Math.floor(tmp % RADIX)].push(items[j])
      if (maxLength && tmp > 0) {
        maxLength = false
      }
    }

    var a = 0
    for (var b = 0; b < RADIX; b++) {
      var buck = buckets[b]
      for (var k = 0; k < buck.length; k++) {
        items[a] = buck[k]
        a++
      }
    }
    placement *= RADIX
  }
  return items
}

// Implementation of radixSort

var ar = [5, 6, 7, 8, 1, 2, 12, 14]
// Array before Sort
console.log(ar)
radixSort(ar)
// Array after sort
console.log(ar)

LANGUAGE:

DARK MODE: