From 0124077e9d3f8540871b423df33e82bb391b034a Mon Sep 17 00:00:00 2001 From: augusto <93066036+alpheratz0@users.noreply.github.com> Date: Fri, 1 Jul 2022 20:49:35 -0300 Subject: [PATCH] clean up again & just compute searchText.split(" ") once (#805) --- content/_index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/_index.md b/content/_index.md index c18d933..1b3cd09 100644 --- a/content/_index.md +++ b/content/_index.md @@ -28,15 +28,16 @@ document.addEventListener("DOMContentLoaded", () => { search.addEventListener("input", () => { // grab search input value const searchText = search.value.toLowerCase().trim(); + const searchTerms = searchText.split(" "); const hasFilter = searchText.length > 0; artlist.classList.toggle("list-searched", hasFilter); // for each recipe hide all but matched - let matchCount = 0; recipes.forEach(recipe => { const recipeName = recipe.textContent.toLowerCase(); - const isMatch = searchText.split(' ').every(term => recipeName.includes(term)); + const isMatch = searchTerms.every(term => recipeName.includes(term)); + recipe.hidden = !isMatch; recipe.classList.toggle("matched-recipe", hasFilter && isMatch); })