Skip to content

Commit 18968af

Browse files
author
AndreyGeonya
committed
quickselect jsdoc
1 parent 2849ea9 commit 18968af

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/searching/quickselect.js‎

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

4-
// O(n)
4+
/**
5+
* Returns the n-th smallest element of list within
6+
* lo..hi inclusive (i.e. lo <= n <= hi).<br><br>
7+
* Time complexity: O(N).
8+
*
9+
* @example
10+
*
11+
* var quickselect = require('path-to-algorithms/src/searching/'+
12+
* 'quickselect').quickselect;
13+
* var result = quickselect([5, 1, 2, 2, 0, 3], 1, 0, 5);
14+
* console.log(result); // 1
15+
*
16+
* @public
17+
* @module searching/quickselect
18+
* @param {Array} arr Input array.
19+
* @param {Number} n A number of an element.
20+
* @param {Number} lo Low index.
21+
* @param {Number} lo High index.
22+
* @return Returns n-th smallest element.
23+
*/
524
function quickselect(arr, n, lo, hi) {
625
function partition(arr, lo, hi, pivotIdx) {
726
function swap(arr, i, j) {
@@ -45,4 +64,4 @@
4564
}
4665
exports.quickselect = quickselect;
4766

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

0 commit comments

Comments
 (0)