Design comparison
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.
Community feedback
- @Dark-LoverPosted about 3 years ago
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.
0 - @Dark-LoverPosted about 3 years ago
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 :)
0@kunsansangPosted about 3 years ago@Dark-Lover hey, very appreciate when you leave me an idea. If u already read my code you would have seen that I am actually using 3 arrays to contain the difference countries:
- validCountryArr: I copy all the country to this array and set it default to working with both searching and filtering. (My purpose is want this two function working together).
- invalidCountryArr: to contains invalid countries is spliced from 1st arr when searching.
- invalidCountryFilterArr: to contains invalid countries is spliced from 1st arr when filtering. I split invalid countries into 2 arr because it won't affect the other arr when I use 2 function the same time. What should I do with Filter as you advice. I don't get it. Feel free to folk my code in github. ✨✨
0
Please log in to post a comment
Log in with GitHubJoin 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