sanjay555

rmDuplicate.html

Jan 9th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.40 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.   <title>Document</title>
  9.   <script type="text/javascript">
  10.     let a = ["a", "c", "c", "c", "a", "a"];
  11.     let count = 0;
  12.  
  13.     function rmDuplicate(rawData) {
  14.       for (var i = 0; i <= a.length; i++) {
  15.        for (var j = 0; j <= a.length; j++) {
  16.          if (a[i] == a[j]) {
  17.            count = count + 1;
  18.            console.log(`IF Count:::> ${count}`);
  19.           } else {
  20.             count = 0;
  21.             console.log(
  22.               " else count = " + count + " because " + a[j] + " at position"
  23.             );
  24.           }
  25.           if (count >= 3) {
  26.             console.log(` a[j]: ${a[j]} and count: ${count}`);
  27.             break;
  28.           }
  29.         }
  30.         if (count >= 3) {
  31.           // console.log('count = ' + count + 'because ' + a[i] + 'at position' + i + ' to next 3');
  32.           console.log("count " + count + ", Now removing...");
  33.  
  34.           for (var k = 0; k <= count; k++) {
  35.            console.log(`before:  ${a}`);
  36.            a.splice(i, 1);
  37.            console.log(`after ${a}`);
  38.          }
  39.  
  40.          count = 0;
  41.          i = 0;
  42.        }
  43.        console.log(` Now array: ${a}`);
  44.      }
  45.    }
  46.    rmDuplicate(a);
  47.  </script>
  48. </head>
  49.  
  50. <body>
  51.  
  52. </body>
  53.  
  54. </html>
Add Comment
Please, Sign In to add comment