I have this Array:
var arr = ['a','a','b','b','b','c','d','d','a','a','a'];
I wish this output:
[
['a','a'],
['b','b','b'],
['c'],
['d','d'],
['a','a','a'],
]
Obs.: Notice that I dont want group all the repeat values. Only the sequential repeated values.
Can anyone help me?
Solution with
Array.prototype.reduce()
and a view to the former element.You can reduce your array like this:
see Array.prototype.reduce().