Finding indexes of each element in a multidimensional array in ruby
- by Shreyas Satish
Eg
:a=[["hello", "world"], ["good", "lord"], ["hello", "lord"]]
I need to find and record the indexes of each word with respect to the super-array.
i.e
hello => 0,2
world => 0
lord => 1,2.
here's my shot ,but its very amateurish and lengthy.
all_tokens=tokens.flatten
all_tokens.each do|keyword|
tokens.each do|token_array|
if token_array.include?keyword
x << i
end
i=i+1
end
y[k] = x.clone
y=y.clear
end