0
Why does this work only 4/5 cases
I have a code for no numerals and it works only 4 out of 5 cases string = gets string.gsub!(/1/, "one") string.gsub!(/0/, "zero") string.gsub!(/2/, "two") string.gsub!(/3/, "three") string.gsub!(/4/, "four") string.gsub!(/5/, "five") string.gsub!(/6/, "six") string.gsub!(/7/, "seven") string.gsub!(/8/, "eight") string.gsub!(/9/, "nine") string.gsub!(/10/, "ten") puts string
2 Answers
+ 2
10 will not be ten, but rather one zero because you put string.gsub!(/1/, "one") and string.gsub!(/0/, "zero") before string.gsub!(/10/, "ten"). They will be found first and modify the string before 10 can get matched.
Put string.gsub!(/10/, "ten") before string.gsub!(/1/, "one")
+ 1
Ohhh i get it thank you