Created
December 26, 2019 18:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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