Is it just 1 letter? Then just upcase
?
[1] pry(main)> "2000-h1".upcase
=> "2000-H1"
Question
q = ["2002-h2","2002-h1", "2000-h1", "2005-h2", "2000-h2", "2005-h1"]
q.sort_by { |a| a }.collect{|u| u}
=> ["2000-h1", "2000-h2", "2002-h1", "2002-h2", "2005-h1", "2005-h2"]
when i'm using titleize its removing Hyphen symols
q.sort_by { |a| a }.collect{|u| u.titleize}
=> ["2000 H1", "2000 H2", "2002 H1", "2002 H2", "2005 H1", "2005 H2"]
i want like this type
=> ["2000-H1", "2000-H2", "2002-H1", "2002-H2", "2005-H1", "2005-H2"]
i want sort q values
How to fix this one?
Solution
Is it just 1 letter? Then just upcase
?
[1] pry(main)> "2000-h1".upcase
=> "2000-H1"
OTHER TIPS
You can write this even shorter, because .sort_by { |a| a }
returns the same than just .sort
and .collect { |a| a.upcase }
returns the same than .map(&:upcase)
q = ["2002-h2","2002-h1", "2000-h1", "2005-h2", "2000-h2", "2005-h1"]
q.sort.map(&:upcase)
#=> ["2000-H1", "2000-H2", "2002-H1", "2002-H2", "2005-H1", "2005-H2"]