forked from lighthouse-labs/finstagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyellowpager.rb
44 lines (32 loc) · 1.07 KB
/
yellowpager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def numbers_for_string(input_string)
if input_string.length > 10
puts "FALSE"
end
mappings = [{letter: ["A", "B", "C"], number: "2"},
{letter: ["D", "E", "F"], number: "3"},
{letter: ["G", "H", "I"], number: "4"},
{letter: ["J", "K", "L"], number: "5"},
{letter: ["M", "N", "O"], number: "6"},
{letter: ["P", "Q", "R", "S"], number: "7"},
{letter: ["T", "U", "V"], number: "8"},
{letter: ["W", "X", "Y", "Z"], number: "9"},]
output_result = ""
input_string.split("").each do |input_char|
input_char = input_char.upcase
output_num = ""
mappings.each do |next_mapping|
if next_mapping[:letter].include?(input_char)
output_num = next_mapping[:number]
end
end
output_result += output_num
end
return output_result
end
puts "Yellow Pager!"
test_strings = ["helloworld", "Amazing Way", "Lighthouse"]
test_strings.each do |some_string|
puts "Start: #{some_string}"
result_number = numbers_for_string(some_string)
puts "Finish: #{result_number}"
end