2
In an array
a = [[1,"José"],[2,"Pedro"],[3,"Maria"],[4,"Lauro"],[2,"Pedro"],
[5,"Léo"],[1,"José"],[6,"Caio"]]
how to get a new array b that shows the positions of the indices with the repeating (equal) arrays? , in which case the array b would look like this:
b = [[0,6],[1,4]]
I was able to make a clone of the array by comparing each position, but it was somewhat time-consuming and it also has the original positions that are included in array b making it the same array with the same positions, so it wasn’t cool.
Show what you’ve done.
– Guilherme Bernal
So it works, I’m trying to take the addiction of the for to use each that is more elegant and functional, I’ve changed several codes replacing the for, mainly because of the indexes that I get lost with them a lot. 'a1 = a.clone b = Array.new cont_i = 0 for i in (0..a.length-1) for j in ((i+1)..a1.length-1) if a[i] == a1[j] b[cont_i] = [i, j] cont_i += 1 end&end end&#;'
– MJAGO