I have an array of elements:
arr = ["one", "two", "three", "one", "two", "one"]
I want to replace duplicates with empty strings in array:
output= ["", "", "three", "", "", ""]
Here is my code:
let obj = {}
for(let i=0; i<arr.length; i++) {
let a = arr[i];
if(obj[a]) obj[a]+=1
else obj[a]=1
}
let output = []
for(let i=0; i<arr.length; i++) {
output[i] = obj[arr[i]] > 1 ? "" : arr[i];
}
Is this a better approach or is there a way to improve the performance?