Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
How can I filter specific emails from an array?

I'm trying to get from an array of multiple emails string this effect if there is more than one email that ends with the same domain name of the email do not show me that filter for example:

const db = ['example@example.com', 'example2@example.com'];

const check = ['example3@example.com', 'another@anotherdomain.com'];

function findNotSimilar(check, db) {

const arr = check.filter((item) => db.indexOf(item) === -1);
return arr;

}

this returns ['example3@example.com', 'another@anotherdomain.com'], but I would like to return just ['another@anotherdomain.com'] array because the email ending with the same domain name

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Here is the solution. But regarding the domains.. you have to consider domains with 2 parts like '.co.uk' in comparison with simple '.com'.

function Test() {
    const db = ['example@example.com', 'example2@example.com'];
    const check = ['example3@example.eu', 'another@anotherdomain.com'];
    const dbFiltered = db.map(x => x.split('@')[1].split('.').slice(0, -1).join('.')).filter((x, y, z) => z.indexOf(x) === y);
    const arr = check.filter((item) => dbFiltered.map(x => item.indexOf(x) === -1).every(x => x === true));
    return arr;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Working Demo :

const db = ['example@example.com', 'example2@example.com'];
const check = ['example3@example.com', 'another@anotherdomain.com'];

// Split the array elements with domain name and creating a new array.
const formatDb = db.map((item) => item.split('@')[1]);

// Filtered out the element with different domain name.
const arr = check.filter((item) => formatDb.indexOf(item.split('@')[1]) === -1);

console.log(arr);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda