Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!