From 9645287d888044084283fabec316168fec8fe99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 12 Aug 2017 19:57:30 -0700 Subject: [PATCH] Use a Set() instead of array We only want unique values, Set is better for this --- assets/static/filters.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/assets/static/filters.js b/assets/static/filters.js index a6fe35373..2cde60940 100644 --- a/assets/static/filters.js +++ b/assets/static/filters.js @@ -93,7 +93,7 @@ function appendFilterToHistory(text) { if (!text || !appendsEnabled) return false; // final filter list we'll save to storage - var filterList = [ text ]; + var filterList = new Set([ text ]); // get current history list from storage and append it to our final list // of filters, but avoid duplicates @@ -101,17 +101,14 @@ function appendFilterToHistory(text) { if (history) { const historyArr = history.split("\n"); for (var i = 0; i < historyArr.length; i++) { - var h = historyArr[i]; - if (filterList.indexOf(h) < 0) { - filterList.push(h); - } + filterList.add(historyArr[i]); } } // truncate the history to up to 11 elements - filterList = filterList.slice(0, 11); + const filterListTrunc = Array.from(filterList).slice(0, 11); - historyStorage.setItem(historyKey, filterList.join("\n")); + historyStorage.setItem(historyKey, filterListTrunc.join("\n")); } function setFilters() {