Skip to content

Commit dd0100e

Browse files
drytikovegonSchiele
authored andcommitted
fix algoritm (egonSchiele#45)
1 parent 3499ab6 commit dd0100e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

04_quicksort/ES6/05_quicksort.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ const quickSort = (array) => {
33
return array;
44
}
55
const pivot = array[0];
6-
const less = array.filter(item => item < pivot);
7-
const greater = array.filter(item => item > pivot);
8-
9-
return [...quickSort(less), pivot, ...quickSort(greater)];
6+
const keysAreLessPivot = array.slice(1).filter(key => key <= pivot);
7+
const keysAreMorePivot = array.slice(1).filter(key => key > pivot);
8+
return [...quickSort(keysAreLessPivot), pivot, ...quickSort(keysAreMorePivot)];
109
};
1110

1211
console.log(quickSort([10, 5, 2, 3])); // [2, 3, 5, 10]

0 commit comments

Comments
 (0)