fix algoritm (#45)
This commit is contained in:
committed by
Aditya Bhargava
parent
3499ab656a
commit
dd0100e471
@@ -3,10 +3,9 @@ const quickSort = (array) => {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
const pivot = array[0];
|
const pivot = array[0];
|
||||||
const less = array.filter(item => item < pivot);
|
const keysAreLessPivot = array.slice(1).filter(key => key <= pivot);
|
||||||
const greater = array.filter(item => item > pivot);
|
const keysAreMorePivot = array.slice(1).filter(key => key > pivot);
|
||||||
|
return [...quickSort(keysAreLessPivot), pivot, ...quickSort(keysAreMorePivot)];
|
||||||
return [...quickSort(less), pivot, ...quickSort(greater)];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(quickSort([10, 5, 2, 3])); // [2, 3, 5, 10]
|
console.log(quickSort([10, 5, 2, 3])); // [2, 3, 5, 10]
|
||||||
|
|||||||
Reference in New Issue
Block a user