Quantcast
Channel: Hacker News
Viewing all articles
Browse latest Browse all 25817

Show HN: Illustrated Quicksort algorithm

$
0
0

0. function quicksort(list) {

1. if (list.length < 2) {

2. return list;

3. }

4.

5. const pivot = random(list);

6. const less = list.filter(i => i < pivot);

7. const greater = list.filter(i => i > pivot);

8.

9. return [

10. ...quicksort(less),

11. pivot,

12. ...quicksort(greater)

13. ];

14. }


Viewing all articles
Browse latest Browse all 25817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>