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

199
Visualizações
Checking for multiple conditions with JavaScript includes() method inside filter() method

I am trying to filter out words that include zz or ZZ but can't quite get it to work. I am trying to use includes() within the filter() method. I'm not sure if the || operand is the correct choice here.

function removeZZ (str){
  let splitStr = str.split(" ")
  let noBuzz = splitStr.filter(word => !word.includes("zz") ||!word.includes("ZZ") )
  return noBuzz.join(" ")
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can use word.toLowerCase().includes

const str = "wed zzAA ZZSS 34f34f"

function removeZZ(str) {
  return str
    .split(" ")
    .filter(word => !word.toLowerCase().includes("zz"))
    .join(" ");
}
console.log(removeZZ(str))

With your approach you need to use && instead of ||

const str = "wed zzAA ZZSS 34f34f"

function removeZZ(str) {
  let splitStr = str.split(" ")
  let noBuzz = splitStr.filter(word => !word.includes("zz") && !word.includes("ZZ"))
  return noBuzz.join(" ")


}
console.log(removeZZ(str))

about 4 years ago · Juan Pablo Isaza Relatório

0

Or simply you can make each word lowercase and check if it includes 'zz'. Try the following example.

function removeZZ (str){
  let splitStr = str.split(" ")
  let noBuzz = splitStr.filter(word => !word.toLowercase().include('zz'))
  return noBuzz.join(" ")
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Your logic is a bit inverted by using the || instead of && operator.

Instead you could write this:

let noBuzz = splitStr.filter(word => !word.includes("zz") && !word.includes("ZZ") )

Or use an Array of blocked words instead:

let noBuzz = splitStr.filter(word => !["zz", "ZZ"].includes(word))

Or, as they are the same and only the case is different, try a Regex:

let noBuzz = splitStr.filter(word => !word.match(/zz/i))
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