Jacob Carpenter’s Weblog

October 22, 2014

ES6 Quicksort

Filed under: Uncategorized — Jacob @ 9:13 pm

Playing around with some ES6 features:

function quicksort([head, ...tail]) {
   if (head === undefined)
      return [];

   return [...quicksort([for (x of tail) if (x < head) x]),
      head,
      ...quicksort([for (x of tail) if (x >= head) x])];
}

Destructuring, rest, spread, comprehensions… I’m looking forward to writing more ES6.

Create a free website or blog at WordPress.com.