MCPcopy
hub / github.com/mgechev/javascript-algorithms / partition

Function partition

src/searching/quickselect.js:25–41  ·  view source on GitHub ↗
(arr, lo, hi, pivotIdx)

Source from the content-addressed store, hash-verified

23 */
24 function quickselect(arr, n, lo, hi) {
25 function partition(arr, lo, hi, pivotIdx) {
26 function swap(arr, i, j) {
27 var temp = arr[i];
28 arr[i] = arr[j];
29 arr[j] = temp;
30 }
31 var pivot = arr[pivotIdx];
32 swap(arr, pivotIdx, hi);
33 for (var i = lo; i < hi; i += 1) {
34 if (arr[i] < pivot) {
35 swap(arr, i, lo);
36 lo += 1;
37 }
38 }
39 swap(arr, hi, lo);
40 return lo;
41 }
42
43 if (arr.length <= n) {
44 return undefined;

Callers 1

quickselectFunction · 0.70

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected