From feb1570c487a109975295c52aea1bf8df459752f Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sat, 10 Aug 2019 22:07:26 -0700 Subject: [PATCH] Simplify function implementation --- src/webui/www/private/scripts/misc.js | 32 +++++++++------------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/webui/www/private/scripts/misc.js b/src/webui/www/private/scripts/misc.js index b2b9e8b3c..32f4dc24d 100644 --- a/src/webui/www/private/scripts/misc.js +++ b/src/webui/www/private/scripts/misc.js @@ -176,28 +176,18 @@ function toFixedPointString(number, digits) { */ function containsAllTerms(text, terms) { const textToSearch = text.toLowerCase(); - for (let i = 0; i < terms.length; ++i) { - const term = terms[i].trim().toLowerCase(); - if ((term[0] === '-')) { - // ignore lonely - + return terms.every((function(term) { + const isTermRequired = (term[0] === '+'); + const isTermExcluded = (term[0] === '-'); + if (isTermRequired || isTermExcluded) { + // ignore lonely +/- if (term.length === 1) - continue; - // disallow any text after - - if (textToSearch.indexOf(term.substring(1)) !== -1) - return false; - } - else if ((term[0] === '+')) { - // ignore lonely + - if (term.length === 1) - continue; - // require any text after + - if (textToSearch.indexOf(term.substring(1)) === -1) - return false; - } - else if (textToSearch.indexOf(term) === -1){ - return false; + return true; + + term = term.substring(1); } - } - return true; + const textContainsTerm = (textToSearch.indexOf(term) !== -1); + return isTermExcluded ? !textContainsTerm : textContainsTerm; + })); }