Skip to content

Instantly share code, notes, and snippets.

@wezm
Created May 1, 2015 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wezm/6348f1fcb8c228e75452 to your computer and use it in GitHub Desktop.
Save wezm/6348f1fcb8c228e75452 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/array'
items = ["African", "Ambient", "Asian", "Avant-garde", "Blues", "Breakbeat", "Caribbean", "Comedy", "Country", "Disco", "Downtempo", "Drum & Bass", "Easy listening", "Electro", "Electronic", "Folk", "Hardcore", "Hardstyle", "Hip hop", "House", "Industrial", "Jazz", "Jungle", "Latin", "Pop", "R&B", "Rock", "Soul", "Techno", "Trance"]
letters = ('a'..'z')
puts letters.to_a.map(&:upcase).join(' ')
last_letter = '`' # ` is the char before 'a'
items.in_groups_of(2).each do |group|
next_letter = group.compact.map { |item| item[0].downcase }.last
if next_letter != last_letter
(last_letter.succ..next_letter).each do |letter|
puts %{<a name="#{letter}">}
end
end
last_letter = next_letter
puts group.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment