Last active
May 11, 2016 17:00
-
-
Save albertywu/7117dd22329135747313ab9d105a33dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // quicksort sorting algorithm, in 2 lines of code | |
| let quicksort = ([a, ...as]) => { | |
| if (a == null) return as | |
| return quicksort(as.filter(x => x <= a)) | |
| .concat([a]) | |
| .concat(quicksort(as.filter(x => x > a))) | |
| } | |
| let test1 = [5,1,2,3,5,6]; | |
| let test2 = ['c', 'a', 'm', 'b', 'd', 'p'] | |
| let test3 = [] | |
| console.log(quicksort(test1)) // [1,2,3,4,5,6] | |
| console.log(quicksort(test2)) // ['a', 'b', 'c', 'd', 'm', 'p'] | |
| console.log(quicksort(test3)) // [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment