diff --git a/06 - Type Ahead/index-FINISHED.html b/06 - Type Ahead/index-FINISHED.html index 5902b43936..fe7c2d48ed 100644 --- a/06 - Type Ahead/index-FINISHED.html +++ b/06 - Type Ahead/index-FINISHED.html @@ -23,11 +23,10 @@ .then(data => cities.push(...data)); function findMatches(wordToMatch, cities) { - return cities.filter(place => { - // here we need to figure out if the city or state matches what was searched - const regex = new RegExp(wordToMatch, 'gi'); - return place.city.match(regex) || place.state.match(regex) - }); + const regex = new RegExp(wordToMatch, 'gi'); + + // here we need to figure out if the city or state matches what was searched + return cities.filter(place => place.city.match(regex) || place.state.match(regex)); } function numberWithCommas(x) { @@ -36,8 +35,8 @@ function displayMatches() { const matchArray = findMatches(this.value, cities); + const regex = new RegExp(this.value, 'gi'); const html = matchArray.map(place => { - const regex = new RegExp(this.value, 'gi'); const cityName = place.city.replace(regex, `${this.value}`); const stateName = place.state.replace(regex, `${this.value}`); return `