Last active
September 6, 2019 07:47
-
-
Save okaprinarjaya/dc724e029f6bb6995f0ef481d916e260 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(list) { | |
if (list.length > 0) { | |
const pivot = list.splice(0, 1)[0]; | |
const smaller = quicksort(list.filter(item => item < pivot) || []); | |
const bigger = quicksort(list.filter(item => item >= pivot) || []); | |
return smaller.concat([pivot]).concat(bigger); | |
} else { | |
return []; | |
} | |
} | |
let unsorted_list = [7,1,3,4,2,5,0,6,2,2,2,2,2100,11,10,21,15]; | |
console.log("UNSORTED LIST LENGTH = ", unsorted_list.length); | |
let sorted_list = quicksort(unsorted_list); | |
console.log("SORTED LIST LENGTH = ", sorted_list.length); | |
console.log(sorted_list); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment