How Do I Remove Duplicate Emails and Count the Results?

I have a list of emails saved to a CSV and I would like to first remove any duplicates and then count the number of emails. I currently do this by pasting the list in to a website, but I would like to do the same within the macro.
Here is what I have so far, which does not work.

{
  "Name": "Test CSV and Arrays",
  "CreationDate": "2022-4-14",
  "Commands": [
    {
      "Command": "csvReadArray",
      "Target": "list_cand.csv",
      "Value": "emails",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${emails}",
      "Value": "purple",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var contacts =  ${emails};\n{\n    var contactList = emails.split(',');\n    var newContacts = [];\n    for(var i = 0; i < contactList.length; i++){\n        if(newContacts.indexOf(contactList[i]) === -1)\n            newContacts.push(contactList[i]);\n    }\n    return newContacts;\n}\n\nuniqueContacts(contacts);",
      "Value": "contacts",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${contacts}",
      "Value": "olive",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var t = contacts.split(',');$.unique(t);console.log(t);",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${t}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "",
      "Value": "",
      "Description": "how to read and parse a CSV file from https://stackoverflow.com/questions/37689604/finding-unique-values-in-a-csv"
    },
    {
      "Command": "csvReadArray",
      "Target": "list_cand.csv",
      "Value": "myCSV",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "function solution(A)\n{\n    var lines = A.split(/\\r?\\n/g);\n\n    var counts = {};\n    var multiples = {};\n\n    for (var i=0, ii=lines.length; i<ii; i++)\n    {\n        var splt = lines[i].split(/\\s*\\|\\s*/g);\n        var val = splt[0];\n\n        if (!counts[val]) {\n            counts[val] = 1;\n        } else {\n            counts[val]++;\n            multiples[val] = counts[val];\n        }\n    }\n\n    return multiples;\n}",
      "Value": "multiples",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${multiples}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "",
      "Value": "",
      "Description": "Arrays: see stackoverflow.com and https://code-boxx.com/javascript-read-csv-array-object/"
    }
  ]
}
{
  "Name": "AAAAAAAAAAAAAA",
  "CreationDate": "2022-4-15",
  "Commands": [
    {
      "Command": "csvReadArray",
      "Target": "data_from_array.csv",
      "Value": "TEST",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${TEST}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var a = ${TEST}.toString().match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)/g);\nlet b = [...new Set(a)];\nreturn b;",
      "Value": "A",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${A}",
      "Value": "green",
      "Description": ""
    }
  ]
}

Thank you!
Thank you for solving this very frustrating issue.
(Now I will work on printing the result into a form.)

I also have the same problem, but this code is not working.