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
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))...