Skip to content

Commit ed4ac01

Browse files
author
AndreyGeonya
committed
add bucketsort jsdoc
1 parent 74d1acc commit ed4ac01

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

‎src/sorting/bubblesort.js‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
}
77

88
/**
9-
* The bubblesort algorithm. Complexity O(n^2).
9+
* Bubble sort algorithm.<br><br>
10+
* Complexity: O(N^2).
11+
*
12+
* @example
13+
* var sort = require('path-to-algorithms/src/' +
14+
* 'sorting/bubblesort').bubbleSort;
15+
* console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ]
1016
*
1117
* @public
12-
* @param {array} array Input array
13-
* @returns {array} array Sorted array
18+
* @module sorting/bubblesort
19+
* @param {Array} array Input array.
20+
* @param {Function} cmp Optional. A function that defines an
21+
* alternative sort order. The function should return a negative,
22+
* zero, or positive value, depending on the arguments.
23+
* @return {Array} Sorted array.
1424
*/
1525
function bubbleSort(array, cmp) {
1626
cmp = cmp || comparator;
@@ -29,4 +39,4 @@
2939

3040
exports.bubbleSort = bubbleSort;
3141

32-
}(typeof exports === 'undefined' ? window : exports));
42+
})(typeof window === 'undefined' ? module.exports : window);

‎src/sorting/bucketsort.js‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
(function (exports) {
2+
23
'use strict';
34

4-
/**
5-
* Bucket sort. This algorithm has complexity O(n) in case the
6-
* data is with uniform distribution.
7-
*
8-
* @public
9-
*/
105
var bucketSort = (function () {
116

127
/**
@@ -90,11 +85,20 @@
9085
}
9186

9287
/**
93-
* Sorts given array with bucketsort
88+
* Sorts given array with bucketsort.<br><br>
89+
* Time complexity: O(N) in case the
90+
* data is with uniform distribution.
91+
*
92+
* @example
93+
*
94+
* var sort = require('path-to-algorithms/src/'+
95+
* 'sorting/bucketsort').bucketSort;
96+
* console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ]
9497
*
9598
* @public
96-
* @param {array} array Input array which should be sorted
97-
* @returns {array} Sorted array
99+
* @module sorting/bucketsort
100+
* @param {Array} array Input array which should be sorted.
101+
* @return {Array} Sorted array.
98102
*/
99103
return function (array) {
100104
var buckets = createBuckets(array);
@@ -105,4 +109,4 @@
105109

106110
exports.bucketSort = bucketSort;
107111

108-
}(typeof exports === 'undefined' ? window : exports));
112+
})(typeof window === 'undefined' ? module.exports : window);

0 commit comments

Comments
 (0)