Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const handleSubmit = e => {
- e.preventDefault();
- // make a copy of the list
- let filteredList = [...pokemonList.current];
- // skip type filtering if 'any' is selected
- if (!types.includes('any')) {
- // if AND
- if (searchType === 'and') {
- filteredList = filteredList.filter(pokemon => {
- for (const selectedType of types) {
- if (!pokemon.types.includes(selectedType)) {
- return false;
- }
- }
- return true;
- });
- }
- }
- if (search) {
- const searchTerm = search.toLowerCase();
- filteredList = filteredList.filter(pokemon => pokemon.name.includes(searchTerm));
- }
- setPokemonList(filteredList);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement