Skip to content

Commit 3ab9814

Browse files
author
AndreyGeonya
committed
add countingsort jsdoc
1 parent bce1e66 commit 3ab9814

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/sorting/countingsort.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
(function (exports) {
22
'use strict';
33

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-
*/
104
var countingSort = (function () {
115

126
/**
13-
* Gets the count of the elements into the input array
7+
* Gets the count of the elements into the input array.
148
*
159
* @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.
1812
*/
1913
function getCount(array) {
2014
var count = [];
@@ -27,12 +21,12 @@
2721
}
2822

2923
/**
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.
3125
*
3226
* @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.
3630
*/
3731
function getLessCount(array) {
3832
var less = [];
@@ -46,12 +40,12 @@
4640
}
4741

4842
/**
49-
* Sorts the input array
43+
* Sorts the input array.
5044
*
5145
* @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.
5549
*/
5650
function sort(array, less) {
5751
var result = [];
@@ -71,11 +65,19 @@
7165
}
7266

7367
/**
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 ]
7576
*
7677
* @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.
7981
*/
8082
return function (array) {
8183
var less = getLessCount(getCount(array));
@@ -85,4 +87,4 @@
8587

8688
exports.countingSort = countingSort;
8789

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

0 commit comments

Comments
 (0)