Skip to content

Instantly share code, notes, and snippets.

@AyaMorisawa
Created November 29, 2015 05:30
Show Gist options
  • Save AyaMorisawa/806e5faec330ae199ef5 to your computer and use it in GitHub Desktop.
Save AyaMorisawa/806e5faec330ae199ef5 to your computer and use it in GitHub Desktop.
function quicksort([x, ...xs]: number[]): number[] {
return typeof x === 'undefined' ? [] : (() => {
const smallerSorted = quicksort(xs.filter(a => a <= x));
const biggerSorted = quicksort(xs.filter(a => a > x));
return [...smallerSorted, x, ...biggerSorted];
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment