Created
November 3, 2020 06:30
-
-
Save ufo22940268/b43fe95045eb784a89e95dad9035a4d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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