I am trying to get the index of string which has duplicate characters. But if I have same characters it keeps returning the index of first occurrence of that character
str = "sssaadd"
str.each_char do |char|
puts "index: #{str.index(char)}"
end
Output:-
index: 0
index: 0
index: 0
index: 3
index: 3
index: 5
index: 5