Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda