Quicksort

Sort an array using the quicksort algorithm with average O(n log n) time complexity.

Code

Algorithms
const quicksort = a => a.length <= 1 ? a : [
  ...quicksort(a.slice(1).filter(x => x <= a[0])),
  a[0],
  ...quicksort(a.slice(1).filter(x => x > a[0]))
];
return quicksort(arr);

Parameters

Array to sort

Browser·fetch() may be limited by CORS

More JavaScript Snippets