Skip to main content
Participant
May 6, 2006
Question

Removing Duplicates in a List

  • May 6, 2006
  • 2 replies
  • 444 views
Hello. I have a series of 4 lists of numbers, and I want to combine the lists into one long list, with no duplicates (if there are any).

For example, given the following lists:
a - (1,2,3,4,5,6,7)
b - (1,3,5,7,9,11,13)
c - (2, 8, 10, 15, 16)
d - (2, 3, 4, 5)

I want to get a single list e comprised of (1,2,3,4,5,6,7,8,9,10,11,13,15,16) using CFML. If this is something better accomplished within a CFSCRIPT, that would be fine. I just can't find the information to do this in the documentation I have.

Thanks!
    This topic has been closed for replies.

    2 replies

    May 8, 2006
    I have a function that I use for this task. You could easily change it to accept an array of lists rather than a single list, if desired, and to sort (or you can just sort the result yourself).

    Inspiring
    May 6, 2006
    You can do this with some native Java, but do please be aware that this wont maintain the list order.

    Inspiring
    May 6, 2006
    NewList ="";
    for (i =1; lte ListLen(ListA; i = i + 1) {
    if (ListFind(NewList, ListGetAt(ListA, i) is false) {
    NewList = ListAppend(NewList(ListGetAt(ListA, i));
    }
    }
    Loop through other lists and do the same thing. Like Simon's solution, this won't be sorted.