MCPcopy Index your code
hub / github.com/davidshariff/computer-science / QuickSort

Function QuickSort

Sorting/QuickSort.js:3–34  ·  view source on GitHub ↗
(inputArr)

Source from the content-addressed store, hash-verified

1(function() {
2
3 var QuickSort = function(inputArr) {
4
5 var len = inputArr.length,
6 left = [],
7 right = [],
8 pivot;
9
10 if (len === 0) {
11 return inputArr;
12 }
13
14 pivot = inputArr[0];
15
16 // partition values into upper and lower
17 // start at second element, since we are using first element as the pivot
18 for (var i = 1; i < len; i++) {
19
20 if (inputArr[i] <= pivot) {
21 left.push(inputArr[i]);
22 }
23 else {
24 right.push(inputArr[i]);
25 }
26
27 }
28
29 left = QuickSort(left);
30 right = QuickSort(right);
31
32 return left.concat(pivot, right);
33
34 };
35
36 var myArray = [2, 4, 1, 6, 8, 5, 9, 3, 4];
37

Callers 1

QuickSort.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected