i would like to Replace duplicates items with different values.
eg arr = [1,1,1,1,2,2,2,3] i want to replace the duplicates with R
So the result looks like this arr = [1,R,R,R,2,R,R,3]
right now I'm using this approach:
arr = [1,1,1,1,2,2,2,3]
let previous = 0;
let current = 1;
while (current < arr.length) {
if (arr[previous] === arr[current]) {
arr[current] = 'R';
current += 1;
} else if (arr[previous] !== arr[current]) {
previous = current;
current += 1;
}
}
i wondering if there is different approach for to achieve that. for Example using Lodash (uniqwith, uniq).
Thanks