[ 1, 2, 1, 1, 2, 1, 1 ] how to find adjacent elements in an array

Nice, I knew there was a neat functional solution out there somewhere! To match my spec above:

~findIt2 = { |arr|
	var sizes = arr.separate { |a, b| a.first != b.first }.collect { |a| a.size };
	var indices = [0] ++ sizes.integrate.drop(-1);
	var values = arr[indices];
	[indices, sizes, values].flop.select { |a| a[1] > 1 }
};
2 Likes