0

I have a list of table names, which are out of order. How can I get them in the correct logical order?

Raw data:

Item 5
Item 1
Item New
Item 2
Item 3
Item 1534
Item 6

After doing Item.find().sort('itemName ASC')

Item 1
Item 1534
Item 2
Item 3
Item 5
Item 6
Item New

Expected order:

Item 1
Item 2
Item 3
Item 5
Item 6
Item 1534
Item New

How can I achieve the expected result ?

M.Octavio
  • 1,780
  • 2
  • 25
  • 39

1 Answers1

0

I think you need Natural sort

Here is article about that: http://www.davekoelle.com/alphanum.html

Some theory: http://web.archive.org/web/20130826203933/http://my.opera.com/GreyWyvern/blog/show.dml/1671288

And Stack questions you may find interesting:

  1. Underscore.js sort an array of objects alphanumerically
  2. Javascript : natural sort of alphanumerical strings
Community
  • 1
  • 1
Bonanza
  • 1,601
  • 14
  • 23