Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

alpha numeric sort

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've asked about this on the Datatables forums but got no response and it's driving me crazy. I have a field that contains alpha-numeric values in the form A1L, A1R, B2L, B2R......C12L, C12R, and so on. As returned from the stored procedure they come back like so:

Obviously, I want them to sort based on the first alpha character then the middle digit or digits. I got that much working with this code:

Almost there. Now I get this:

..etc. so the first part is correct but the L and R are still coming out random. So I tried to modify the code like so:


But it's ignoring the third comparison. A jsfiddle is here. If I pass "A1R" and "A1L" to the function I get zero returned and I can't figure out why.
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without looking at the fiddle or a whole lot of thought, I think what you want to do is to only consider the 3rd part if the first two parts match exactly.

But I may be talking out of my hat...
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I do this:

Then the evaluation works. I get either 1 or -1 depending on the order of "L" and "R". So there is something else wrong with the more complex function. Maybe this one will come to me tonight. One of those "dream in code" things and I'll wake up knowing the solution. For now it's time to go home and work on Python homework.
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 14 always returns. The code after it is unreachable.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Matola wrote:Line 14 always returns. The code after it is unreachable.


Yep, it came to me this morning, but thanks for spotting it. I took one look at it and fixed it in about a minute. Sometimes you just have to walk away and sleep on it.
This works perfectly:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic