Skip to content

Instantly share code, notes, and snippets.

@ZhihaoLau
Created October 8, 2017 15:50
Show Gist options
  • Save ZhihaoLau/76ac03df341ca6917920a0d8ca2b2719 to your computer and use it in GitHub Desktop.
Save ZhihaoLau/76ac03df341ca6917920a0d8ca2b2719 to your computer and use it in GitHub Desktop.
quickSort in ES6 favor
function quickSort(list) {
if (list.length < 2) return list
let medIdx = Math.floor(list.length / 2),
medItem = list[medIdx],
newList = [...list.slice(0, medIdx), ...list.slice(medIdx+1)],
left = newList.filter(item => item <= medItem),
right = newList.filter(item => item > medItem)
return [...quickSort(left), medItem, ...quickSort(right)]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment