removing duplicate array values (vbscript)

removing duplicate array values.

 Function removeDupsArray(sList)
  Dim sNewList, aList, maxItems
  aList = split(sList,",")
  maxItems = UBound(aList)
  For x = 0 To maxItems
   If InStr(sNewList,(aList(x) & ",")) <= 0 Then
    sNewList = sNewList & aList(x) & ","
   End If
  Next
  removeDupsArray = Left(sNewList,Len(sNewList)-1)
 End Function
 
 function dedupe_list(input)
 {
 
  var count = 0;
  var mainlist = input;
  mainlist = mainlist.replace(/\r/gi, "\n");
  mainlist = mainlist.replace(/\n+/gi, "\n");
  
  var listvalues = new Array();
  var newlist = new Array();
  
  listvalues = mainlist.split("\n");
  
  var hash = new Object();
  
  for (var i=0; i<listvalues.length; i++)
  {
   if (hash[listvalues[i].toLowerCase()] != 1)
   {
    newlist = newlist.concat(listvalues[i]);
    hash[listvalues[i].toLowerCase()] = 1
   }
   else { count++; }
  }
  newlist.sort();
  return newlist.join("\r\n");
 }
 
Dim aFrs, aCln
    Dim nIdx
  
    aFrs = Array( "Phil", "Harry", "Fred", "Phil" )
    aCln = cleanArray( aFrs )
  
    WScript.Echo "aFrs", Join( aFrs, " * " )
    WScript.Echo "aCln", Join( aCln, " * " )
  
  Function cleanArray( aFrs )
    Dim dicFrs
    Dim nIdx
  
    Set dicFrs = CreateObject( "Scripting.Dictionary" )
    For nIdx = 0 To UBound( aFrs )
        If Not dicFrs.Exists( aFrs( nIdx ) ) Then dicFrs.Add aFrs( nIdx ), ""
    Next
    cleanArray = dicFrs.Keys
  End Function
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s