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.