Stable Sorting in JavaScript…

I saw this article via a Stack Overflow answer. It’s a method for producing a stable sort order from an unstable sorting algorithm. The geek inside me meant I had to share…

The basic premise is that if you store the pre-sort positions, then in the sorting algorithm if you find two elements are equal, you use the original position to determine which to show first. Pretty clever yet simple, which is the kind of coding I like.

Here’s the link to the article: http://blog.vjeux.com/2010/javascript/javascript-sorting-table.html

For those of you wondering why on Earth I’m looking at stable sorting algorithms in JavaScript, I suggest you keep an eye on my blog through next week, or come to my MarkLogic World lightning talk on my MLDB JavaScript API for MarkLogic.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s