Ervin Kosch


ASP function to show only the differences between arrays

Posted in Geek News by me on the April 26th, 2007

ASP function to

<%

‘ Return an array of items that are NOT duplicated in an array
function ShowDiff(array1, array2)
dim d, item, thekeys, build_arr

‘ Build Array - a command that will be Execute
build_arr = “anArray = ARRAY(”

‘ Loop through the first array, add to output
for x = lbound(array1) to ubound(array1)
build_arr = build_arr & “array1(” & x & “), ”
next

‘ Loop through the second array, add to output
for y = lbound(array2) to ubound(array2)
build_arr = build_arr & “array2(” & y & “), ”
next

‘ Cleanup last comma
build_arr = left(build_arr, len(build_arr) - 2)
build_arr = build_arr & ” )”

‘ Excute the build statement
execute build_arr

‘ Show differences
set d = CreateObject(”Scripting.Dictionary”)
d.removeall
d.CompareMode = 0
for each item in anArray
if not d.Exists(item) then
d.Add item, item
else
d.Remove item
end if
next
thekeys = d.keys
set d = nothing
ShowDiff = thekeys
end function

%>

Leave a Reply

You must be logged in to post a comment.