I need to convert a structure to a list so that I ...
# cfml-general
m
I need to convert a structure to a list so that I can remove duplicates bit I can't find anything that seems to do this. Anyone help? Seems to be lots available for arrays etc but nothing for struct to list
s
Can you explain what duplicates within the structure you are attempting to remove?
m
I have a structure of emails but the structure contains duplicate emails So this is an example of the structure:
Email1: mauro@gmail.com Email2: mauro@gmail.com Email3: James@gmail.com I only need to check the values (i.e. the email for duplicate)
w
can think of a few others, but same result
m
Cheers guys that's perfect 🙏
s
That is magical, but how does that actually work? 🙂 Please enlighten me!
a
Copy code
function getUniqueEmailsFromStructValues(struct) {
    return struct.reduce((st, _, email) => st.insert(email, "", true), {}).keyList()
}
With tests: https://trycf.com/gist/f9d0ee26458f4098f20f59ef20ae4a6e/acf2021?setupCodeGistId=816ce84fd991c2682df612dbaf1cad11&theme=monokai
🙏 1
w
when using square bracket notation with structs, you have a lot of latitude on what strings you can use for the key name. i'm just leveraging that fact, plus the fact that any duplicate key values just overwrite the existing ones to store the unique 'values' as struct 'keys'. then just use the built in structkeylist() to get the keys as a normal list
🎉 1
👏🏼 1
that's another way above, i just thought it would read more simply with the more primitive approach i used
m
Cheers everyone 🙏
e
Mine is no where as cool as Adams, but does the same thing in tag format. 😄 https://trycf.com/gist/76900a999b74526046f525ff857d6de7/acf2021?theme=monokai
👍🏼 1