andrewplummer/Sugar — Issue #103: Should String.compare(otherString) not ignore case?
Author: D1plo1d
Created: 2012-02-06 23:53:36+00:00
State: open

Note: I am using coffescript for these examples because this is more or less directly pulled from my code.

Problem
------------
Alphabetizing an array of strings is unnecessarily difficult.

For example:

```coffeescript
["a", "b", "C" , "d"].sort (a,b) -> a.compare(b) # => ["C", "a", "b", "d"]
```

This is not the expected behavior IMO. Rare are the occassions that I want to sort capatilized strings before uncapitalized strings.

Work around
------------------
```coffeescript
["a", "b", "C" , "d"].sort (a,b) -> a.toLowerCase().compare(b.toLowerCase()) # => ["a", "b", "C", "d"]
```
This works as expected but feels a bit too verbose for me.

Suggestion 1 (aka kill all verbosity with fire)
-------------------------------------------------------------
Add a Array.alphabetize function to sort arrays of strings into alphabetical order using Object.toString().

Suggestion 2
--------------------
Change String.compare to be case insensitive by default.

PS
-----
This is my first day playing around with Sugar (coming from _.js) and as a big active support fan boy this stuff is awesome. I love what you guys are doing to my code complexity (seriously, excluding the above issue sugar is so far so awesome!). Thanks!