diff --git a/portfolio/src/main/webapp/assets/js/testimonials.js b/portfolio/src/main/webapp/assets/js/testimonials.js index 33d82d5..2af8cf4 100644 --- a/portfolio/src/main/webapp/assets/js/testimonials.js +++ b/portfolio/src/main/webapp/assets/js/testimonials.js @@ -53,15 +53,23 @@ function filterFunction() { filter = input.value.toUpperCase(); ul = document.getElementById("testimonialUl"); li = ul.getElementsByTagName("li"); + const stringArray = []; for (i = 0; i < li.length; i++) { blockQuote = li[i].getElementsByTagName("blockquote")[0]; p = blockQuote.getElementsByTagName("p")[0]; txtValue = p.textContent || p.innerText; - if (txtValue.toUpperCase().indexOf(filter) > -1) { - li[i].style.display = ""; - } else { - li[i].style.display = "none"; - } + stringArray.push(txtValue.toUpperCase()); + + // set all of the list items to disapear so that they can be made to reapear later + li[i].style.display = "none"; + } + + // TODO: give user feedback that only one term is supported https://github.com/jackdavidweber/step-portfolio/pull/26#discussion_r443534422 + const matches = distanceOfArr(stringArray, filter, 2) + + // make matches re-appear + for (let i=0; i < matches.length; i++){ + li[matches[i].arrIndex].style.display = ""; } } @@ -171,11 +179,13 @@ function findEditDistance(w1,w2){ */ function distanceOfArr(arrSentences, term, maxED){ + let tracker = 0 let retArray = [] for (const sentence of arrSentences){ let ed = minEditDistanceWord(sentence, term) if(ed < maxED){ - retArray.push({"sentence": sentence, "editDistance": ed}); + retArray.push({"sentence": sentence, "editDistance": ed, "arrIndex": tracker}); + tracker++; } } return retArray;