Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [Javascript] Shouldn't there be a sort option on objects




Hi Dave,


On 06/02/11 19:19, Dave M G wrote:
Just spent the last hour or so going mental trying to apply a sort() on
an object. Turns out it only works on arrays.

Okay, fine, but then it turns out, as far as I can tell by looking
around the net, that there is no sort() on objects, which seems to me a
bit of a miss. I thought objects were supposed to be more dynamic and
flexible.


As I know nothing about Javascript, I'm probably not going to be as much help as Stephen's replies. Ignore what I say if it's no help to you. :-)

For what it's worth, you can sort arbitrary objects that are in an array in C/C++ (i.e., array of objects). In C, you give it a sort function that tells it what the object looks like. i.e.,

http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/

Of course, these objects need to be placed in an array in some initial linear order. If it was in some kind of associative array, then you would need to pull them out and throw them in an array for qsort () to work.

Perhaps languages like Perl and Python can do something like this -- I've never tried. Examples of sorting objects in C/C++ are somewhat rare; most examples stick with easy cases...

Ray




Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links