Skip to content

Instantly share code, notes, and snippets.

@billyma128
Last active October 1, 2016 17:29
Show Gist options
  • Save billyma128/0ba626759e1e8b85a445 to your computer and use it in GitHub Desktop.
Save billyma128/0ba626759e1e8b85a445 to your computer and use it in GitHub Desktop.
使用ES6实现快排
function quicksort(head,...tail) {
if (!head) return [];
return quicksort(...tail.filter( _ => _ <= head))
.concat([head])
.concat(quicksort(...tail.filter( _ => _ > head )))
}
// 传入参数quicksort(1,4,2,3)或quicksort(...[1,4,2,3])
@liubiantao
Copy link

liubiantao commented Oct 1, 2016

const quicksort = ([head, ...tail]) => {
  if (!head) return [];
  return quicksort(tail.filter( _ => _ <= head))
    .concat(head)
    .concat(quicksort(tail.filter( _ => _ > head )))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment