code to get repeating or duplicate or non unique and non repeating or non duplicate or unique in an array using javascript
Asked
Active
Viewed 84 times
-3
-
2What you have tried so far,need to add the code you have tried – flyingfox Nov 18 '22 at 11:39
-
He removed the code. – Ankit Nov 18 '22 at 12:00
1 Answers
0
I think the output is coming for this code. Forgive me if I've used any unwanted things. I'm a budding developer. :)
let start = [1, 1, 2, 1, 3, 4, 5, 6, 5, 5];
let one = [];
let two = [];
let three = [];
for (let i = 0; i < start.length; i++) {
if (!one.includes(start[i])) {
one.push(start[i]);
} else {
two.push(start[i]);
}
}
for (let j = 0; j < two.length; j++) {
if (!three.includes(two[j])) {
three.push(two[j]);
}
}
console.log('Unique elements are ' + one);
console.log('Non Unique elements are ' + three);