11
11
*/
12
12
function quickSort ( items , left = 0 , right = items . length - 1 ) {
13
13
if ( ! Array . isArray ( items ) ) {
14
- throw new Error ( 'Please input a valid list or array.' ) ;
14
+ throw new Error ( 'Please input a valid list or array.' )
15
15
}
16
16
17
17
if ( left < right ) {
18
- let pivotIndex = partition ( items , left , right ) ;
19
- quickSort ( items , left , pivotIndex - 1 ) ;
20
- quickSort ( items , pivotIndex + 1 , right ) ;
18
+ let pivotIndex = partition ( items , left , right )
19
+ quickSort ( items , left , pivotIndex - 1 )
20
+ quickSort ( items , pivotIndex + 1 , right )
21
21
}
22
22
23
- return items ;
23
+ return items
24
24
}
25
25
26
26
/**
@@ -34,18 +34,18 @@ function quickSort(items, left = 0, right = items.length - 1) {
34
34
* @return {number } - The index of the pivot element after partitioning.
35
35
*/
36
36
function partition ( items , left , right ) {
37
- const pivot = items [ right ] ;
38
- let i = left - 1 ;
37
+ const pivot = items [ right ]
38
+ let i = left - 1
39
39
40
40
for ( let j = left ; j < right ; j ++ ) {
41
41
if ( items [ j ] <= pivot ) {
42
- i ++ ;
43
- [ items [ i ] , items [ j ] ] = [ items [ j ] , items [ i ] ] ;
42
+ i ++
43
+ ; [ items [ i ] , items [ j ] ] = [ items [ j ] , items [ i ] ]
44
44
}
45
45
}
46
46
47
- [ items [ i + 1 ] , items [ right ] ] = [ items [ right ] , items [ i + 1 ] ] ;
48
- return i + 1 ;
47
+ ; [ items [ i + 1 ] , items [ right ] ] = [ items [ right ] , items [ i + 1 ] ]
48
+ return i + 1
49
49
}
50
50
51
- export { quickSort } ;
51
+ export { quickSort }
0 commit comments