The following function compares the new list of items with the old and finds the differences:
- Items that have been removed from the old list
- Items that have been added to the new list (not in the original list).
I wrote two loops for this, and they produced the following output:
oldItems = "an, old, list" ---> Items to delete: 'an, old'
newItems = "a, new, list" ---> Items to create: 'new'
The first problem: it ashould be displayed in the created elements, but I believe, because this is a substring anthat it does not receive.
The second problem (?) Is that I am doing two loops seems inefficient. Can I reorganize the code?
public function testList() hint="Compares two lists to find the differences."
{
local.oldItems = "a, new, list";
local.newItems = "an, old, list";
local.toDelete = "";
local.toCreate = "";
for (local.i = 1; local.i LTE ListLen(local.newItems, ", "); local.i++)
{
if (! ListContains(local.oldItems, ListGetAt(local.newItems, local.i, ", ")))
{
local.toCreate = ListAppend(local.toCreate, ListGetAt(local.newItems, local.i, ", "));
}
}
for (local.i = 1; local.i LTE ListLen(local.oldItems, ", "); local.i++)
{
if (! ListContains(local.newItems, ListGetAt(local.oldItems, local.i, ", ")))
{
local.toDelete = ListAppend(local.toDelete, ListGetAt(local.oldItems, local.i, ", "));
}
}
writeDump(var="Items To Delete: '" & local.toDelete & "'");
writeDump(var="Items To Create: '" & local.toCreate & "'", abort=true);
}