Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created December 26, 2019 18:12
Show Gist options
  • Select an option

  • Save venelrene/7022373212b4c82941b2fa213d413b44 to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/7022373212b4c82941b2fa213d413b44 to your computer and use it in GitHub Desktop.
In this kata you are required to, given a string, replace every letter with its position in the alphabet. If anything in the text isn't a letter, ignore it and don't return it. "a" = 1, "b" = 2, etc.
def alphabet_position(text)
text.upcase.gsub(/[A-Z]/).map {|m| m.ord-64}.join(" ")
end
#### before refactor
# def alphabet_position(text)
# alphabet = ('a'..'z').to_a
# text.downcase.chars.map {|l| alphabet.index(l.next) }.compact.join(" ")
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment