|
1 | 1 | (function (exports) { |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | - /** |
5 | | - * Counting sort algorithm. It's with complexity O(n) but it's |
6 | | - * correct only for array of integers. |
7 | | - * |
8 | | - * @public |
9 | | - */ |
10 | 4 | var countingSort = (function () { |
11 | 5 |
|
12 | 6 | /** |
13 | | - * Gets the count of the elements into the input array |
| 7 | + * Gets the count of the elements into the input array. |
14 | 8 | * |
15 | 9 | * @private |
16 | | - * @param {array} array The input array |
17 | | - * @returns {array} count The count of each element from the input array |
| 10 | + * @param {Array} array The input array. |
| 11 | + * @return {Array} The count of each element from the input array. |
18 | 12 | */ |
19 | 13 | function getCount(array) { |
20 | 14 | var count = []; |
|
27 | 21 | } |
28 | 22 |
|
29 | 23 | /** |
30 | | - * Gets the count of the elements which are less than a given |
| 24 | + * Gets the count of the elements which are less than a given. |
31 | 25 | * |
32 | 26 | * @private |
33 | | - * @param {array} array The input array |
34 | | - * @returns {array} less The count of the elements which |
35 | | - * are less than each element from the input |
| 27 | + * @param {Array} array The input array. |
| 28 | + * @return {Array} less The count of the elements which. |
| 29 | + * are less than each element from the input. |
36 | 30 | */ |
37 | 31 | function getLessCount(array) { |
38 | 32 | var less = []; |
|
46 | 40 | } |
47 | 41 |
|
48 | 42 | /** |
49 | | - * Sorts the input array |
| 43 | + * Sorts the input array. |
50 | 44 | * |
51 | 45 | * @private |
52 | | - * @param {array} array Input which should be sorted |
53 | | - * @param {array} less Count of the less elements for each element |
54 | | - * @returns {array} result The sorted input |
| 46 | + * @param {Array} array Input which should be sorted. |
| 47 | + * @param {Array} less Count of the less elements for each element. |
| 48 | + * @return {Array} The sorted input. |
55 | 49 | */ |
56 | 50 | function sort(array, less) { |
57 | 51 | var result = []; |
|
71 | 65 | } |
72 | 66 |
|
73 | 67 | /** |
74 | | - * Sorts a given array |
| 68 | + * Counting sort algorithm. It's correct only |
| 69 | + * for array of integers.<br><br> |
| 70 | + * Time complexity: O(N). |
| 71 | + * |
| 72 | + * @example |
| 73 | + * var sort = require('path-to-algorithms/src/' + |
| 74 | + * 'sorting/countingsort').countingSort; |
| 75 | + * console.log(sort([2, 5, 1, 3, 4])); // [ 1, 2, 3, 4, 5 ] |
75 | 76 | * |
76 | 77 | * @public |
77 | | - * @param {array} array Array which should be sorted |
78 | | - * @returns {array} array Sorted array |
| 78 | + * @module sorting/countingsort |
| 79 | + * @param {Array} array Array which should be sorted. |
| 80 | + * @return {Array} Sorted array. |
79 | 81 | */ |
80 | 82 | return function (array) { |
81 | 83 | var less = getLessCount(getCount(array)); |
|
85 | 87 |
|
86 | 88 | exports.countingSort = countingSort; |
87 | 89 |
|
88 | | -}(typeof exports === 'undefined' ? window : exports)); |
| 90 | +})(typeof window === 'undefined' ? module.exports : window); |
0 commit comments