Program to return the unique values of odd occurrences of elements present in an array in Javascript
Let's consider the given input array is ['aa','bb','aa','bb','aa','cc','cc','ddd'], now if you want to return only the unique values of odd occurences of the given array elements. For example, we have to return ['aa','ddd'] as aa appears 3x and ddd 1x times.
let arr=['aa','bb','aa','bb','aa','cc','cc','ddd'];
let newarr=[];
for(let i =0; i < arr.length;i++){
let counter=0;
for(let j=0; j<arr.length; j++){
if(arr[i]===arr[j]){
counter++;
}
}
if((counter%2) !=0){
newarr.push( arr[i]);
}
}
console.log([...new Set(newarr)])
Try yourself and check the output here @ https://onecompiler.com/javascript/3x6k2egwd