Skip to content
Advertisement

Group sequential repeated values in Javascript Array

I have this Array:

JavaScript

I wish this output:

JavaScript

Obs.: Notice that I dont want group all the repeat values. Only the sequential repeated values.

Can anyone help me?

Advertisement

Answer

You can reduce your array like this:

JavaScript

see Array.prototype.reduce().

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement