What is your desired output structure? Something like this?
// input array
[2, 3, 5, 5]
// desired output array
[ [ 2, 2, 5] ] // array containing arrays structured as [index of first repeat occurrence, number of adjacent repeats, value that is repeated]
// input
[1, 2, 1, 1, 1, 2, 1, 1]
// desired output
[ [2, 3, 1], [6, 2, 1] ] // your example has a mistake I think? the second repeated chunk starts at index 6, not 7
Or do you want a Dictionary associating the repeated chunks with their named properties (index of first repeat occurrence, # of repeats, etc.)?
If I understood OP correctly, this returns the wrong value for both inputs, see my post above. ~findIt always only returns one array even though it should return multiple arrays if there are multiple chunks of repeated values (one for every chunk). Also, it returns
[value at index of first repeated chunk, number of repeats, value at index+1 of first repeated chunk]
instead of
[index of first repeat occurrence, number of adjacent repeats, value that is repeated]
which is how I interpreted OP’s requirement. I also don’t get why ~findIt needs an index argument?
Edit: I should probably wait for OP to respond instead of being pedantic about your solution
x = [1, 2, 1, 1, 1, 2, 1, 1];
// if you just want the groups
y = x.separate { |a, b| a.first != b.first };
// if you want the sizes
z = x.separate { |a, b| a.first != b.first }.collect { |a| a.size };
// if you want the indices
i = [0] ++ z.integrate.drop(-1);
// sizes and indices as subarrays
[z, i].flop
// select all larger than 1
[z, i].flop.select { |a| a.first > 1 }
// indices and sizes as dictionary
[i, z].flop.flat.asDict
// select all larger than 1
[i, z].flop.flat.asDict.select { |a| a > 1 }
// values at the indices left as an exercise