Advertisement
Guest User

Untitled

a guest
Apr 29th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const handleSubmit = e => {
  2. e.preventDefault();
  3.  
  4. // make a copy of the list
  5. let filteredList = [...pokemonList.current];
  6.  
  7. // skip type filtering if 'any' is selected
  8. if (!types.includes('any')) {
  9. // if AND
  10. if (searchType === 'and') {
  11. filteredList = filteredList.filter(pokemon => {
  12. for (const selectedType of types) {
  13. if (!pokemon.types.includes(selectedType)) {
  14. return false;
  15. }
  16. }
  17. return true;
  18. });
  19. }
  20. }
  21.  
  22. if (search) {
  23. const searchTerm = search.toLowerCase();
  24. filteredList = filteredList.filter(pokemon => pokemon.name.includes(searchTerm));
  25. }
  26.  
  27. setPokemonList(filteredList);
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement