Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let a = ["a", "c", "c", "c", "a", "a", "a"];
- let count = 0;
- function rmDuplicate(rawData) {
- for (var i = 0; i <= a.length; i++) {
- for (var j = 0; j <= a.length; j++) {
- if (a[i] == a[j]) {
- count = count + 1;
- } else {
- count = 0;
- }
- if (count >= 3) {
- break;
- }
- }
- if (count >= 3) {
- // console.log('count = ' + count + 'because ' + a[i] + 'at position' + i + ' to next 3');
- console.log("count " + count + ", Now removing...");
- for (var k = 0; k <= count; k++) {
- console.log(`Before : ${a}`)
- a.splice(i, 1);
- console.log(`After : ${a}`)
- }
- count = 0;
- i = 0;
- }
- console.log(` Now array: ${a}`);
- }
- }
- rmDuplicate(a);
Add Comment
Please, Sign In to add comment