Skip to content

Commit 3eff8fd

Browse files
committed
Migrate doctest for BucketSort.js
(also remove inline test driver code)
1 parent 402ab5c commit 3eff8fd

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

Sorts/BucketSort.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
/*
2-
[Wikipedia says](https://en.wikipedia.org/wiki/Bucket_sort#:~:text=Bucket%20sort%2C%20or%20bin%20sort,applying%20the%20bucket%20sorting%20algorithm.&text=Sort%20each%20non%2Dempty%20bucket.): Bucket sort, or bin sort, is a sorting algorithm that works by distributing the
3-
elements of an array into a number of buckets. Each bucket is then sorted individually, either using
4-
a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a
5-
distribution sort, and is a cousin of radix sort in the most to least significant digit flavour.
6-
Bucket sort is a generalization of pigeonhole sort. Bucket sort can be implemented with comparisons
7-
and therefore can also be considered a comparison sort algorithm. The computational complexity estimates
8-
involve the number of buckets.
9-
10-
Time Complexity of Solution:
11-
Best Case O(n); Average Case O(n); Worst Case O(n)
12-
13-
*/
14-
151
/**
16-
* bucketSort returns an array of numbers sorted in increasing order.
2+
* BucketSort implementation.
3+
*
4+
* Wikipedia says: Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array
5+
* into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by
6+
* recursively applying the bucket sorting algorithm. It is a distribution sort, and is a cousin of radix sort in the
7+
* most to least significant digit flavour. Bucket sort is a generalization of pigeonhole sort. Bucket sort can be
8+
* implemented with comparisons and therefore can also be considered a comparison sort algorithm. The computational
9+
* complexity estimates involve the number of buckets.
10+
*
11+
* @see https://en.wikipedia.org/wiki/Bucket_sort#:~:text=Bucket%20sort%2C%20or%20bin%20sort,applying%20the%20bucket%20sorting%20algorithm.&text=Sort%20each%20non%2Dempty%20bucket.
12+
*
13+
* Time Complexity of Solution:
14+
* Best Case O(n); Average Case O(n); Worst Case O(n)
1715
*
1816
* @param {number[]} list The array of numbers to be sorted.
1917
* @param {number} size The size of the buckets used. If not provided, size will be 5.
2018
* @return {number[]} An array of numbers sorted in increasing order.
2119
*/
22-
function bucketSort (list, size) {
20+
export function bucketSort (list, size) {
2321
if (undefined === size) {
2422
size = 5
2523
}
@@ -60,5 +58,3 @@ function bucketSort (list, size) {
6058
}
6159
return sorted
6260
}
63-
64-
export { bucketSort }

0 commit comments

Comments
 (0)