Monday, May 14, 2012

Javascript sort alphabetically matching the beginning of string then alphabetically for contained text

I need help sorting through some data.
Say I type "piz" in a searchfield. I get in return and array with all the entries that contain "piz".



I now want to display them in the following order:



pizza 
pizzeria
apizzetto
berpizzo


First the items that start with what I typed in alphabetical order then the ones that contain what I typed in alphabetical order.



Instead if I sort them alphabetically I get the following



apizzetto
berpizzo
pizza
pizzeria


Does anyone know how to do this?
Thanks for your help.





No comments:

Post a Comment