Haskell Quicksort in JavaScript

This is a note titled "2018-04-25-haskell-quicksort-in-javascript" taken from my note Library. Return to Library.

Haskell is a really neat language! In fact, you can implement quicksort in just one line.

While this is tremendously inefficient, I thought it would be fun to create a JS version of the one-liner, should I ever need it in an interview.

const quicksort = ([h, ...arr]) => [h, ...arr].length
  ? [ ...quicksort(arr.filter(a => h >= a)), h,
      ...quicksort(arr.filter(a => h < a)) ]
  : []