I am reviewing the drill to strengthen my logical thinking. As a beginner, I would appreciate it if you could let me know if you have any questions.
Use the index method to create a method that returns the number of characters "qiita" appears from the left in any string.
find_qiita("xxxqiitaxxx") → 4 find_qiita("qiitaxxxxxx") → 1 find_qiita("qitaxxqiita") → 7
def find_qiita(str)
puts str.index("qiita") + 1
end
The index method returns a number counting from 0 at the beginning of the string, so you need to do + 1
.
Recommended Posts