My goal is to convert letters within words in an array into their corresponding number values so that:
["I", "like", "elephants"]
turns into
[[18], [21, 18, 20, 14], [14, 21, 14, 25, 17, 10, 23, 29, 28]]
How can I attain my goal?
This is my current code:
words = ["I", "like", "elephants"]
seperate_words = []
converted_words = []
words.each do |word|
seperate_words.push(word.split(//))
end
puts seperate_words.to_s
seperate_words.each do |word|
word.each do |letter|
converted_words.push(letter.to_i 36)
end
end
puts converted_words.to_s
I cannot separate the words as sub-arrays; I get:
[18, 21, 18, 20, 14, 14, 21, 14, 25, 17, 10, 23, 29, 28]