How to Implement QuickSort in JS
QuickSort is one one of the most common and most efficient sorting algorithms.
It helps to think about QuickSort in a real world situation in order to understand it. Let’s say you have a group of people, and you want to order them from tallest to shortest. How would you do that?
If you were to use the QuickSort implementation, you would pick a random person out of the group. You would ask everyone taller than that person to line up on the right, and everyone shorter on the left. You would then have two groups, and one lone person in the middle.
After this, you would repeat the process until the groups had one or no people in them. You would then join the groups, and finally you would have the group ordered from tallest to shortest.
Now, let’s break that into code.
You have an array of numbers.

First, to remove the edge cases, you are going to return the elements if there are one or none elements in the array.

You are going to single out the first element in the array as the pointer. You have two other arrays. A more and a less array.

As you loop through the array, you put everything less than the pointer in the less array, and everything more than it in the more array.

Finally, you use recursion to call the same method on your newly formed groups. Once they are done being sorted, you rejoin them using the concat method.

And just like that, you have a QuickSort algorithm.

