-4

How can I search for a duplicate in a given string using a scriptlet?

ScripletInput= a,b,c,a

Here the letter 'a' is repeating. If it is repeating more than once, then it should exit, else it can go ahead.

Vibes
  • 33
  • 6

1 Answers1

0

Please see Remove occurrences of duplicate words in a string

The code below will remove duplicates in a string.

<script type="text/javascript">
    str=prompt("Enter String::","");
    arr=new Array();
    arr=str.split(",");
    unique=new Array();
    for(i=0;i<arr.length;i++)
    {
        if((i==arr.indexOf(arr[i]))||(arr.indexOf(arr[i])==arr.lastIndexOf(arr[i])))
            unique.push(arr[i]);   
    }
    unique.join(",");
    alert(unique);
</script>
TylerH
  • 20,799
  • 66
  • 75
  • 101
BlooB
  • 955
  • 10
  • 23
  • Thank you for your time :) Appreciate it. I'm using HP OO and I have to use scriptlet which be in below format – Vibes Jun 22 '17 at 06:24
  • if (action.match(/aclrequest/)){ scriptletResponse = "aclrequest"; } if (action.match(/vlan/)) { scriptletResponse = "vlan"; } if (action.match(/firewall/)) { scriptletResponse = "firewall"; } if (action.match(/Error/)) { scriptletResponse = "dataerror"; } ... IS it possible to find duplicate with the snippet provided? – Vibes Jun 22 '17 at 06:24