Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created June 3, 2022 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/8723c3e9c4ded09d16311e07a71137f3 to your computer and use it in GitHub Desktop.
Save crutchcorn/8723c3e9c4ded09d16311e07a71137f3 to your computer and use it in GitHub Desktop.
A naive implementation of bucket sort
function bucketSort(arrToSort) {
const buckets = {}
for (let num of arrToSort) {
buckets[num] = buckets[num] ?? [];
buckets[num].push(num);
}
let newArr = []
for (let i of Object.keys(buckets)) {
newArr = newArr.concat(buckets[i])
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment