Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert a Vanity Phone Number With Letters to One With Numbers Only
# https://gist.github.com/sshaw/29d6f7379771e3b4596e228b626bcf9a
def convert(chr)
chr = chr.upcase
# subtract "A"
n = (chr.ord - 65) / 3
# account for #7 & #9 which have 4 chars
n -= 1 if chr == "S".freeze || chr == "V".freeze || chr >= "Y".freeze
(n + 2).to_s
end
puts "180044STERN".gsub(/[a-z]/i) { |chr| convert(chr) }
puts "555AXYZ".gsub(/[a-z]/i) { |chr| convert(chr) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.