sanjay555

Untitled

Jan 9th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let a = ["a", "c", "c", "c", "a", "a", "a"];
  2. let count = 0;
  3.  
  4. function rmDuplicate(rawData) {
  5.   for (var i = 0; i <= a.length; i++) {
  6.     for (var j = 0; j <= a.length; j++) {
  7.       if (a[i] == a[j]) {
  8.         count = count + 1;
  9.       } else {
  10.         count = 0;
  11.       }
  12.       if (count >= 3) {
  13.         break;
  14.       }
  15.     }
  16.     if (count >= 3) {
  17.       // console.log('count = ' + count + 'because ' + a[i] + 'at position' + i + ' to next 3');
  18.       console.log("count " + count + ", Now removing...");
  19.  
  20.       for (var k = 0; k <= count; k++) {
  21.         console.log(`Before : ${a}`)
  22.         a.splice(i, 1);
  23.         console.log(`After : ${a}`)
  24.       }
  25.  
  26.       count = 0;
  27.       i = 0;
  28.     }
  29.     console.log(` Now array: ${a}`);
  30.   }
  31. }
  32. rmDuplicate(a);
Add Comment
Please, Sign In to add comment