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

194
Visualizações
array every() with includes() issues

Hey people so i've spent a bit too much time trying to find a solution for this and I'd like to know if anyone can help me.

So the problem is, I have 2 arrays, first one with multiple words from an address and another one I built with word I entered in an input, it is returning true if I put the exact same word in the input as it is in the string array but I would like it to return true if it partially match too, for example I have "CENTER" and "RACHEL" in the array of string if I write "CEN EL in the input because it would partially match 2 of the array elements

here's the code i've been trying to put together

        function checker(arr, words) {
            return words.every(v => arr.includes(v));
        }

        this.shippingAddress.forEach(address => {
            const stringBuild = `${address.name} ${address.display_address} ${address.phone}`;
            const arrayString = stringBuild.split(' ');
            if (checker(arrayString, words)) {
                _results.push(address);
            }
        });

An example of input would be for the array arrayString:

[
    0: "CENTER"
    1: "MANIKI"
    2: "BRUCHESI"
    3: "2225,"
    4: ""
    5: "STREET"
    6: "RACHEL"
    7: "EAST,"
    8: "CITY"
    9: "STUFF,"
    10: "STUFF"
    11: "STUFF"
    12: "STUFF"
    13: "STUFF"
]

for the array words:

[
    0: "CEN"
    1: "EL"
    
]

and the output would be true because CEN and EL passing in the checker would be included in the first array but it only work if I put the full words in

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

0

If I understand correctly, you want to return true if every word in the array is partially (or totally) matched?

For every word that must be matched, I would test the array of typed words, and see if at least one of the typed words partially matches the target. I'd use a regex, and also make it case-insensitive with "i" :

const checkArray = ["center","rachel"];

const isOK = (typedWords) => checkArray.every( word1 => typedWords.some( word2 => new RegExp(word2, "i").test(word1)))

console.log(isOK([ "ent" , "rac" ]))
console.log(isOK([ "AaAa" , "BbBb" ]))

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