I need to pack if there are at least two adjacent numbers that are the same in format <number : number_of_occurrences >.
This is my input:
[2,2,2,3,4,3,3,2,4,4,5]
And the expected result:
"2:3,3,4,3:2,2,4:2,5"
So far I have tried:
a = [1, 1, 1, 2, 2, 3, 2, 3, 4, 4, 5]
a.each_cons(2).any? do |s , t|
if s == t
If it is equal, try a counter, perhaps, but it does not work.
source
share