live searching and filter using vanilla js

Solution retrospective
There's still a bug that I haven't fixed yet. When filtering more than one times without clear the current filter then the issues will comes. I am hopefully you guy can let me know where did I miss something, what do you think about this solution. Thanks alot.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @Dark-Lover
u can use just one function, something like this:
filterData(region,data){
let newData= data.filter((element)=> element.region === region);
return newData;
}
newData will contain only countries that passes the condition, in this case, only countries form that region will be returned.
this is just a way of doing things. u may find a better way.
- @Dark-Lover
hey, nice try.. to fix that problem, try to refactor the filter function u have used. the best way is the take a copy of the array containing all countries data and try to filter them using the Js filter method Array.prototype.filter() so that it will return only countries that have region === to region clicked by the user. i hope that was helpful. keep coding :)
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord