Skip to content

Instantly share code, notes, and snippets.

@ufo22940268
Created November 3, 2020 06:30
Show Gist options
  • Save ufo22940268/b43fe95045eb784a89e95dad9035a4d7 to your computer and use it in GitHub Desktop.
Save ufo22940268/b43fe95045eb784a89e95dad9035a4d7 to your computer and use it in GitHub Desktop.
let inputs = [1, 4, 2, 7, 5]
function quickSortImpl(nums, pivot) {
if (nums.length == 0) {
return []
}
return [...quickSortImpl(nums.filter(n => n < nums[pivot]), 0), nums[pivot], ...quickSortImpl(nums.filter((n, i) => n >= nums[pivot] && i != pivot), 0)]
}
function quickSort(nums) {
return quickSortImpl(nums, 0)
}
let r = quickSort(inputs)
console.log('r: ' + JSON.stringify(r, null, 4) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment