Skip to content

Commit 769c213

Browse files
authored
switch shift to pop
according to my test, pop is faster than shift, especially when the array is very long.
1 parent 6fe7df3 commit 769c213

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/algorithms/sorting/quick-sort/QuickSort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export default class QuickSort extends Sort {
1919
const rightArray = [];
2020

2121
// Take the first element of array as a pivot.
22-
const pivotElement = array.shift();
22+
const pivotElement = array.pop();
2323
const centerArray = [pivotElement];
2424

2525
// Split all array elements between left, center and right arrays.
2626
while (array.length) {
27-
const currentElement = array.shift();
27+
const currentElement = array.pop();
2828

2929
// Call visiting callback.
3030
this.callbacks.visitingCallback(currentElement);

0 commit comments

Comments
 (0)