Question

The following code found that it was not be able to sort an array.

For some reasons, the last item "Aland Islands" was located in the last for this array, but it should be located in between "Afghanistan" and "Albania". And this occurs just in case of using iso3166 like below, but does not occur in scratching. Any ideas?

$ which ruby
~/.rvm/rubies/ruby-1.9.3-p362/bin/ruby

$ cat test.rb
#!/usr/bin/env ruby
# coding: utf-8

require 'iso3166'

countries = ISO3166::Country::all.map do |c|
  c.first
end

p countries.sort

$ ruby test.rb
["Afghanistan", "Albania", ... etc ... "Zambia", "Zimbabwe", "Aland Islands"]
Was it helpful?

Solution

Here's my comment as an answer:

'A'.ord => 65 

versus

'Z'[0].ord => 90

versus

'Åland Islands'[0].ord => 197
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top