I have a JS array with strings, for example:
let a = ["a", "a", "a", "b", "c", "c", "b", "b", "b", "d", "d", "e", "e", "e"]
I need to compare for duplicate strings inside the array, and if a duplicate string exists it will be separated like this :
[ ["a", "a", "a"], ["b"], ["c", "c"], ["b", "b", "b"], ["d", "d"], ["e", "e", "e"] ]
I was trying to compare it with for loop, but I don't know how to write code so that array checks its own strings for duplicates, without an already pre-determined string to compare.
let a = ["a", "a", "a", "b", "c", "c", "b", "b", "b", "d", "d", "e", "e", "e"];
let b = [];
let len = a.length;
for (let i = 0; i < len; i++) {
if (b.indexOf(a[i]) !== 1) {
b.push(a[i]);
}
}
console.log(b)