Skip to content

Instantly share code, notes, and snippets.

@AbeEstrada
Created September 3, 2025 00:55
Show Gist options
  • Save AbeEstrada/259a3c3e230d7956d734feed255ab1b9 to your computer and use it in GitHub Desktop.
Save AbeEstrada/259a3c3e230d7956d734feed255ab1b9 to your computer and use it in GitHub Desktop.
Exercise: Quicksort (Partition)
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