Skip to content

Commit 182f89b

Browse files
author
aestheticw3
authored
square brackets fix (egonSchiele#263)
1 parent 022d97a commit 182f89b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

04_quicksort/javascript/quick_sort/05_quicksort.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
* @returns {Array} Sorted array
77
*/
88
function quicksort(array) {
9-
// base case, arrays with 0 or 1 element are already "sorted"
10-
if (array.length < 2) return array;
11-
// recursive case
12-
let pivot = array[0];
13-
// sub-array of all the elements less than the pivot
14-
let less = array.slice(1).filter(function(el) {
15-
return el <= pivot;
16-
});
17-
// sub-array of all the elements greater than the pivot
18-
let greater = array.slice(1).filter(function(el) {
19-
return el > pivot;
20-
});
21-
return quicksort(less).concat([pivot], quicksort(greater));
9+
// base case, arrays with 0 or 1 element are already "sorted"
10+
if (array.length < 2) return array;
11+
// recursive case
12+
let pivot = array[0];
13+
// sub-array of all the elements less than the pivot
14+
let less = array.slice(1).filter(function (el) {
15+
return el <= pivot;
16+
});
17+
// sub-array of all the elements greater than the pivot
18+
let greater = array.slice(1).filter(function (el) {
19+
return el > pivot;
20+
});
21+
return quicksort(less).concat(pivot, quicksort(greater));
2222
}
2323

24-
console.log(quicksort([10, 5, 2, 3]));
24+
console.log(quicksort([10, 5, 2, 3]));

0 commit comments

Comments
 (0)