Created
September 3, 2025 00:55
-
-
Save AbeEstrada/259a3c3e230d7956d734feed255ab1b9 to your computer and use it in GitHub Desktop.
Exercise: Quicksort (Partition)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickSort(arr) { | |
if (arr.length === 0) return []; | |
const pivot = arr[0]; | |
const left = arr.filter((num, i) => i !== 0 && num < pivot); | |
const equal = arr.filter(num => num === pivot); | |
const right = arr.filter((num, i) => i !== 0 && num > pivot); | |
return [...left, ...equal, ...right]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment