Skip to content

Instantly share code, notes, and snippets.

@thebopshoobop
Created October 2, 2017 06:34
Show Gist options
  • Save thebopshoobop/3e7d3770630349929811b3fa71423500 to your computer and use it in GitHub Desktop.
Save thebopshoobop/3e7d3770630349929811b3fa71423500 to your computer and use it in GitHub Desktop.
const radixSort = arr => {
const maxNum = Math.max(...arr) * 10;
let divisor = 10;
while (divisor < maxNum) {
let buckets = [...Array(10)].map(() => []);
for (let num of arr) {
buckets[Math.floor((num % divisor) / (divisor / 10))].push(num);
}
arr = [].concat.apply([], buckets);
divisor *= 10;
}
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment