{"size": 520, "ext": "js", "max_stars_repo_path": "Javascript/algorithms/bucket_sort.js", "max_stars_repo_name": "nhutnamhcmus/code", "max_stars_repo_stars_event_min_datetime": "2020-10-12T18:33:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T18:33:22.000Z", "max_issues_repo_path": "Javascript/algorithms/bucket_sort.js", "max_issues_repo_name": "nhutnamhcmus/code", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Javascript/algorithms/bucket_sort.js", "max_forks_repo_name": "nhutnamhcmus/code", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.6086956522, "max_line_length": 60, "alphanum_fraction": 0.5423076923}
function bucketSort(array) {
    const n = array.length;
    const allBuckets = new Array(n);
    const sortedArray = [];

    if (n < 2) return array;

    for (let i = 0; i < n; i++) {
        allBuckets[i] = [];
    }

    for (let i = 0; i < n; i++) {
        const index = Math.floor(n * array[i] / 10);
        allBuckets[index].push(array[i]);
    };

    allBuckets.forEach(bucket => {
        insertionSort(bucket);
        bucket.forEach(element => sortedArray.push(element))
    });

    return sortedArray;
}