-1

Need to perform natural sorting using javaScript keeping uppercase before lowercase, I have created plunker for detailed understanding.

I have used natural sorter function answered in the previous post given by kennebec (Javascript : natural sort of alphanumerical strings)

Plunker: plnkr.co/edit/Ls2jRRpHJcOhHhkFl8dC?p=preview

function compare(x, y) {     
      //naturalSorter should return job column sorting as A (uppercase), a(lowercase), A13(alphanum), A13(alphanum), A14(alphanum)
                return naturalSorter(x, y);               
        }

Any help would be appreciated.

Thanks!

Community
  • 1
  • 1
  • `'a' < 'b' && 'A' < 'a'` Run this in your console. It will return *true*. Uppercase is already naturally less than lowercase. Please clarify your question. – Neil Mar 11 '16 at 08:07
  • yes! but even when we try without converting x and y to lowercase, result are not as expected. please see the plunker. – PG Rated Programmer Mar 11 '16 at 08:27
  • Updated plunker (http://plnkr.co/edit/Ls2jRRpHJcOhHhkFl8dC?p=preview) – PG Rated Programmer Mar 11 '16 at 08:34
  • The problem is not the sorter then. Unfortunately, I can't tell you anything more than that. Your plunker example is missing the code in your question, so I can't perform a test to see how you're applying the sort. Update your plunkr or provide a bare-bones example in your question proving that it sorts incorrectly using the naturalSorter. – Neil Mar 11 '16 at 09:44
  • Here is the updated plunker : http://plnkr.co/edit/Ls2jRRpHJcOhHhkFl8dC?p=preview – PG Rated Programmer Mar 11 '16 at 10:02
  • That is the same link as the one above... – Neil Mar 11 '16 at 10:13
  • I was under the impression that you wanted your error fixed. Apparently, I was grossly mistaken. – Neil Mar 11 '16 at 10:37

1 Answers1

0

No need to do the toLowerCase, just return naturalSorter(x, y) should sort in the correct order

gabesoft
  • 1,228
  • 9
  • 6
  • No it did not help me :-( the result are not correctly sorted. Kindly check the plunker. Updated plunker: http://plnkr.co/edit/Ls2jRRpHJcOhHhkFl8dC?p=preview – PG Rated Programmer Mar 11 '16 at 08:30