Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <script type="text/javascript">
- let a = ["a", "c", "c", "c", "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;
- console.log(`IF Count:::> ${count}`);
- } else {
- count = 0;
- console.log(
- " else count = " + count + " because " + a[j] + " at position"
- );
- }
- if (count >= 3) {
- console.log(` a[j]: ${a[j]} and count: ${count}`);
- 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);
- </script>
- </head>
- <body>
- </body>
- </html>
Add Comment
Please, Sign In to add comment