Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Removing Duplicates in a List

New Here ,
May 06, 2006 May 06, 2006
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!
455
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 06, 2006 May 06, 2006
You can do this with some native Java, but do please be aware that this wont maintain the list order.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2006 May 06, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 08, 2006 May 08, 2006
LATEST
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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources