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

94
Views
filter conditions working individually but not together

Please check this filterFunction & let me know how can i improve it. These filter are working individually but not together

const filterFunction = (a) => {
  if (!includeKeyword && !searchVolume && !excludeKeyword && !longtailKeyword){
     return true
  } else if (includeKeyword && !searchVolume){
     return a.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase())
  } else if (!includeKeyword && searchVolume){
     return  a.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume)
  } else if (!searchVolume && excludeKeyword){
    return  !a.text.includes(excludeKeyword)
  } else if (!excludeKeyword && longtailKeyword){
    return  a.text.split(" ").length == longtailKeyword
  }  else {
    return  a.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase()) && a.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume)  && !a.text.includes(excludeKeyword) && a.text.split(" ").length <= longtailKeyword
  }
}

Render Function

postRes.filter(filterFunction).map((data, index) => (

i really appreciate your help in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are currently passing an uninvoked function with an argument and passing this in properly as the filter callback.

I think you could try postRes.filter((a) => filterFunction(a))...

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!