Problem picture

Keypad

Sample input output

`a` = `2`
`b` = `22`
`z` = `9999`

# type(ā€˜cā€™)
output => [222]

type('thanks')
# Output => [8, 44, 2, 66, 55, 7777]

Solution

def type(msg)
  data = {
    'a'=>[2],
    'b'=>[22],
    'c'=>[222],
    'd'=>[3],
    'e'=>[33],
    'f'=>[333],
    'g'=>[4],
    'h'=>[44],
    'i'=>[444],
    'j'=>[5], 
    'k'=>[55],
    'l'=>[555],
    'm'=>[6],
    'n'=>[66],
    'o'=>[666],
    'p'=>[7],
    'q'=>[77],
    'r'=>[777],
    's'=>[8],
    't'=>[88],
    'u'=>[888],
    'v'=>[9],
    'w'=>[99],
    'x'=>[999],
    'y'=>[9999],
    'z'=>[99999]
  }
  result = []
  msg.each_char do |char|
    if data.key?(char)
      result += data[char]
    end
  end
  return result
end

print(type('abc'))

Congratualtions. Problem is solved.

Happy coding :)