Skip to content

Instantly share code, notes, and snippets.

@francois
Last active June 9, 2016 23:22
Show Gist options
  • Save francois/85cd6ab1ed37f960285a1adc8142ac6b to your computer and use it in GitHub Desktop.
Save francois/85cd6ab1ed37f960285a1adc8142ac6b to your computer and use it in GitHub Desktop.

Using the Elm 0.17 REPL, sorting is not in the expected order (Ubuntu 15.10):

$ elm repl
---- elm repl 0.17.0 -----------------------------------------------------------
 :help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> import List
> import String
> List.sortBy String.toLower ["R", "É", "D"]
["D","R","É"] : List String

The "UPPERCASE E WITH ACUTE ACCENT" should be between D and R.

In the browser, I get the same behaviour:

accounts: ["R","É","D"]
sorted accounts: ["D","R","É"]

Pure JavaScript does the same thing:

var a = ["R", "É", "D"]
var b = a.map(function(s) { return s.toLowerCase() })
b
//=> ["r", "é", "d"]
b.sort()
//=> ["d", "r", "é"]

Node v4.4.3 incorrectly sorts as well:

> var a = ["D", "É", "R"]
undefined
> var b = a.map(function(s) { return s.toLowerCase() })
undefined
> b.sort()
[ 'd', 'r', 'é' ]

PostgreSQL is the only software which does the correct thing:

SELECT a FROM (VALUES ('R'), ('É'), ('D')) t0(a) ORDER BY lower(a);
#  a
# ---
#  D
#  É
#  R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment