469,590 Members | 1,949 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Sorting a List

Hi All,

Help me to sort out the contents in the list box.

The list box contains data elements like <first name> + <middle name> +
<last name> as "Balaji Muthu Varathan"

I want to sort it based on user preferences.
ie. either it can be sort by last name or middle name or first name or
in combinations

With regards
Balaji. M

Jul 23 '05 #1
2 1412
JRS: In article <1084535456.689127@sj-nntpcache-5>, seen in
news:comp.lang.javascript, Balaji. M. <bm******@cisco.com> posted at
Fri, 14 May 2004 17:22:53 :
Help me to sort out the contents in the list box.

The list box contains data elements like <first name> + <middle name> +
<last name> as "Balaji Muthu Varathan"

I want to sort it based on user preferences.
ie. either it can be sort by last name or middle name or first name or
in combinations


The standard answer will be to write a comparison function parameterised
by a global variable, or a set of comparison functions chosen by a
global variable, in order to compare two given entries.

If the list is too long, this will waste time, because the function will
for a N element list be called N ln N times, and will have to compute
two keys at each call. It will be better to make a single pass through
the list replacing each element by an object {key, element} where key is
the computed sort key for the current sort order, then to do the default
sort, then do another pass to remove the key. A key might, for example,
be Varathan, Balaji Muthu .

Or so I suspect.

The standard language references cover sort functions.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #2
voyez les expressions rationnelles; (regular expressions) !
GR

Balaji. M. a écrit:
Hi All,

Help me to sort out the contents in the list box.

The list box contains data elements like <first name> + <middle name> +
<last name> as "Balaji Muthu Varathan"

I want to sort it based on user preferences.
ie. either it can be sort by last name or middle name or first name or
in combinations

With regards
Balaji. M


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Xah Lee | last post: by
19 posts views Thread by Owen T. Soroke | last post: by
20 posts views Thread by martin-g | last post: by
5 posts views Thread by lemlimlee | last post: by
5 posts views Thread by jrod11 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.