I am not quite sure what I am missing. Thanks for the help in advance!
# Example:
# encoded_string = "m1i1s2i1s2i1p2i1"
# decoded_string = decode(encoded_string)
# decoded_string # => "mississippi"
# decode("f1o2d1")
# "food"
def decode(string)
new_str = ""
i = 0
while i < string.length
letter = string[i]
num = string[i + 1]
num.times {new_str += letter}
i += 2
end
return new_str
end
num.times {new_str += letter}is executed. For example,decode("f1o2d1") #=> NoMethodError (undefined method 'times' for "1":String). That's becausenumis a string, yet the classStringhas no instance methodtimes. Note that this error message pinpoints the problem.