Skip to content

Commit bce1e66

Browse files
committed
Merge pull request mgechev#35 from AndreyGeonya/doc-pack13
Doc pack13
2 parents 8cab588 + ed4ac01 commit bce1e66

6 files changed

Lines changed: 72 additions & 31 deletions

File tree

‎doc-config.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"./src/primes/",
1414
"./src/others/",
1515
"./src/searching/",
16-
"./src/sets/"
16+
"./src/sets/",
17+
"./src/shuffle/",
18+
"./src/sorting/"
1719
],
1820
"includePattern": ".+\\.js(doc)?$",
1921
"excludePattern": "docs"

‎src/shuffle/fisheryates.js‎

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

45
/**
56
* The shuffling algorithm of
6-
* Fisher-Yates. Complexity O(n)
7+
* Fisher-Yates.<br><br>
8+
* Time complexity: O(N).
9+
*
10+
* @example
11+
* var shuffle = require('path-to-algorithms/src/' +
12+
* 'shuffle/fisheryates').shuffle;
13+
* console.log(shuffle([1, 2, 3, 4, 5])); // shuffled array
714
*
8-
* @param {array} array The array which should be shuffled
9-
* @return {array} The shuffled array.
15+
* @public
16+
* @module shuffle/fisheryates
17+
* @param {Array} array Array which should be shuffled.
18+
* @return {Array} Shuffled array.
1019
*/
1120
function shuffle(array) {
1221
var size = array.length;
@@ -23,4 +32,4 @@
2332

2433
exports.shuffle = shuffle;
2534

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

‎src/shuffle/richarddurstenfeld.js‎

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

45
/**
56
* Shuffle of an array elements.
67
* This algorithm is modified version of Fisher-Yates shuffle
7-
* algorithm and is introduced by Richard Durstenfeld.
8-
*/
9-
10-
/**
11-
* Shuffles an array. Complexity O(n).
8+
* algorithm and is introduced by Richard Durstenfeld.<br><br>
9+
* Time complexity: O(N).
10+
*
11+
* @example
12+
* var shuffle = require('path-to-algorithms/src/shuffle' +
13+
* '/richarddurstenfeld').shuffle;
14+
* console.log(shuffle([1, 2, 3, 4, 5])); // random shuffled
1215
*
13-
* @param {array} array An array which should be shuffled
14-
* @returns {array} Shuffled array
16+
* @public
17+
* @module shuffle/richarddurstenfeld
18+
* @param {Array} array An array which should be shuffled.
19+
* @return {Array} Shuffled array.
1520
*/
1621
function shuffle(array) {
1722
var arraySize = array.length - 1;

‎src/sorting/3-way-string-quicksort.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
(function (exports) {
22
'use strict';
33

4-
/**
5-
* Effective inplace string sorting algorithm.
6-
* The algorithm is NOT stable.
7-
*/
84
var quicksort = (function () {
95

106
function charAt(str, i) {
@@ -48,6 +44,21 @@
4844
quicksort(arr, highPointer + 1, hi, d);
4945
}
5046

47+
/**
48+
* Effective inplace string sorting algorithm.
49+
* Algorithm is NOT stable.
50+
*
51+
* @example
52+
*
53+
* var sort = require('path-to-algorithms/src/sorting'+
54+
* '/3-way-string-quicksort').quicksort;
55+
* console.log(sort(['bb', 'aa', 'cc'])); // [ 'aa', 'bb', 'cc' ]
56+
*
57+
* @public
58+
* @module sorting/3-way-string-quicksort
59+
* @param arr {Array} array which should be sorted.
60+
* @return {Array} Sorted array.
61+
*/
5162
return function sort(arr) {
5263
quicksort(arr, 0, arr.length - 1, 0);
5364
return arr;
@@ -56,4 +67,4 @@
5667

5768
exports.quicksort = quicksort;
5869

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

‎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)