1111 */
1212function quickSort ( items , left = 0 , right = items . length - 1 ) {
1313 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.' )
1515 }
1616
1717 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 )
2121 }
2222
23- return items ;
23+ return items
2424}
2525
2626/**
@@ -34,18 +34,18 @@ function quickSort(items, left = 0, right = items.length - 1) {
3434 * @return {number } - The index of the pivot element after partitioning.
3535 */
3636function partition ( items , left , right ) {
37- const pivot = items [ right ] ;
38- let i = left - 1 ;
37+ const pivot = items [ right ]
38+ let i = left - 1
3939
4040 for ( let j = left ; j < right ; j ++ ) {
4141 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 ] ]
4444 }
4545 }
4646
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
4949}
5050
51- export { quickSort } ;
51+ export { quickSort }
0 commit comments