6
I have an array of emails:
emails = [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
I am using regular expressions to parse domains, and my intention is to create a JSON with the following structure:
json = {
"@domain1.com": ["name1", ..., "nameN"],
...
"@domain2.com": ["name1", ..., "nameN"]
}
I’m iterating over every email in the array emails, and when obtaining the domain, I want to check if it already exists in JSON. If so, add the name
in the array of this domain and, if not, create a new domain and add the name
.
Could someone give me a light on how to do this?
+1 No benchmark this time? :)
– Cmte Cardeal
@Cmtecardeal, not today; because the solutions presented seem to have the same complexity. Disregarding the
substring
of the other reply and thesplit
of mine, O(n). :-)– Luiz Felipe