Created
July 20, 2018 05:02
-
-
Save youngdo212/27d156349f382ff461da5281c390f67a 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
function quickSort(arr){ | |
if(arr.length === 0) return arr; | |
let pivot = arr.pop(); | |
let i = -1; | |
for(j = 0; j < arr.length; j++){ | |
if(arr[j] <= pivot){ | |
i++; | |
[arr[i], arr[j]] = [arr[j], arr[i]]; | |
} | |
} | |
return [...quickSort(arr.slice(0, i+1)), pivot, ...quickSort(arr.slice(i+1))]; | |
} | |
console.log(quickSort([10,80,30,90,40,50,70])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment