sample.js 408 B

12345678910111213
  1. var quicksort = function () {
  2. var sort = function(items) {
  3. if (items.length <= 1) return items;
  4. var pivot = items.shift(), current, left = [], right = [];
  5. while(items.length > 0) {
  6. current = items.shift();
  7. current < pivot ? left.push(current) : right.push(current);
  8. }
  9. return sort(left).concat(pivot).concat(sort(right));
  10. };
  11. return sort(Array.apply(this, arguments));
  12. };