Order must be maintained. Defiants shall be eliminated.
This humble package is inspired by a user named "Klappspaten" on YouTube who, one day, commented on Tom Scott's video as follows:
I recently read a paper on a new linear sorting algorithm: It's called Stalin-Sort. It achieves this by simply eliminating any element that isn't in order.
As the saying goes: "The Internet delivers".
The sort
function takes an array of values, presuming the values are sortable, and a flag defining if the sort should be ascending or descending. It then removes any value that is not in the specified order.