I have an array list which has multiple properties in each array. Please refer to the example below:
FinalArray=[
{ColumnName:'Name',ID:6,TranslatedText:'Name',Category:'Assigned Employee'},
{ColumnName:'Name',ID:7,TranslatedText:'Name',Category:'Requested Employee'},
{ColumnName:'Designation',ID:8,TranslatedText:'Designation',Category:'Employee'},
{ColumnName:'Occupation',ID:9,TranslatedText:'Occupation',Category:'Assigned Employee'},
{ColumnName:'Occupation',ID:10,TranslatedText:'Occupation',Category:'Requested Employee'}
];
My task is to find out consecutive repeated elements (referring to translated text property from array list) and append "rep -" for all the occurrences. So the list would look like this in app:
| Column Name | Category | 
|---|---|
| Rep - Name | Assigned Employee | 
| Rep - Name | Requested Employee | 
| Designation | Employee | 
| Rep - Occupation | Assigned Employee | 
| Rep - Occupation | Requested Employee | 
I am stuck at comparing elements and appending values.
 
                        
You can accomplishes this using a Map, and looping the objects twice:
But, this will prepend
Rep -to all duplicates. If you only want consecutive duplicates only, this is ugly, but it works: