Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = mergeSort;
- function quickSort(arr) {
- if(arr.length < 2)
- return arr;
- var pivotIndex = arr.length - 1;
- for (var i = 0; i < arr.length - 1; i++) {
- if(i >= pivotIndex)
- continue;
- while (arr[i] > arr[pivotIndex]) {
- var tmp = arr[pivotIndex - 1];
- arr[pivotIndex - 1] = arr[pivotIndex];
- arr[pivotIndex] = arr[i];
- pivotIndex -= 1;
- arr[i] = tmp;
- }
- }
- return [...quickSort(arr.slice(0, arr.length / 2)), arr[pivotIndex], ...quickSort(arr.slice(arr.length + 1))];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement