Javascript and ordering

Is there a simple way, a library maybe, for sorting?  I have numeric values I need to order.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
Well, the library is for sure Underscore.js.
The thing is that it does a whole bunch of other stuff and if you only need the sorting then it might be a bit too much.

Otherwise you can always implement your own bubble sort algorithm.
I took the following example from here:
var a = [34, 203, 3, 746, 200, 984, 198, 764, 9];
function bubbleSort(a)
    var swapped;
    do {
        swapped = false;
        for (var i=0; i < a.length-1; i++) {
            if (a[i] > a[i+1]) {
                var temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
                swapped = true;
    } while (swapped);

Open in new window

Here's a working sample of this code:
Julian HansenCommented:
Just interested to know why the javascript sort method is not suitable?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontyWeb Ninja at largeCommented:
if you just have a list of numbers you need to sort, check out the array's sort method:
Alexandre SimõesManager / Technology SpecialistCommented:
True, I didn't read the "I have numeric values I need to order" :)

If they are numbers and actually defined as numbers (not strings containing numbers), then you can use the sort directly.
If what you have is an array of strings, the sort will be by text which will result differently from the numeric sort.
HLRosenbergerAuthor Commented:
Thanks!  that does the trick.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.