0

So I used _.sortBy function but I'm experiencing weird sorting behavior. Seems like it 'collects' all words starting with lower case alphabets, sorts them, then 'collects' all words starting with upper case alphabets, sorts them, then 're-groups' those two sorts and displays them. e.g., so if I have something like:

[{prop:a},{prop:z},{prop:D},{prop:X},{prop:g},{prop:G},{prop:S}]

the sorted result will look something like:

[{prop:a},{prop:g},{prop:z},{prop:D},{prop:G},{prop:S},{prop:X}]

Any insight on this would be really appreciated!

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • http://stackoverflow.com/questions/25873635/underscore-js-case-insensitive-sorting – epascarello Mar 19 '15 at 17:23
  • 1
    I think that's because strings are sorted [lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order). To me, that's not weird at all. Why do you think it's weird? According to you how should the `sortBy` function sort strings? – Aadit M Shah Mar 19 '15 at 18:14
  • Hi Aadit, after using the sortBy function on the example, I was expecting the array to look something like: [{prop:a},{prop:D},{prop:g},{prop:G},{prop:S},{prop:X},{prop:z}] (Ignoring the uppercase and lowercase alphabets). Problem is, I have to show this data on the UI as-is. No uppercase to lowercase conversion must be performed (which would solve this issue, as mentioned in the previous comment) on the data returned by an API call... – Siddharth Dawar Mar 19 '15 at 21:08

0 Answers0