@@ -12,42 +12,25 @@ export function findTerms(queryTokens, suggestionTokens) {
1212 } ) ;
1313 } ) ;
1414
15- const firstMatchedSuggestionToken = unusedSuggestionTokens . find ( function (
16- suggestionToken
17- ) {
18- return suggestionToken . str . indexOf ( queryToken . str ) === 0 ;
19- } ) ;
15+ // We use a for loop here because Array.prototype.find isn't supported in IE9
16+ // And we didn't want to pollute the global scope with a polyfill
17+ let firstMatchedSuggestionToken = null ;
18+ for ( let i = 0 ; i < unusedSuggestionTokens . length ; i ++ ) {
19+ const suggestionToken = unusedSuggestionTokens [ i ] ;
20+ if ( suggestionToken . str . indexOf ( queryToken . str ) === 0 ) {
21+ firstMatchedSuggestionToken = suggestionToken ;
22+ break ;
23+ }
24+ }
2025
2126 termMatches . push ( {
2227 suggestionToken : firstMatchedSuggestionToken ,
2328 queryToken : queryToken
2429 } ) ;
2530 }
2631
27- // const termMatches = queryTokens.map(function(queryToken) {
28- // const firstMatchedSuggestionToken = suggestionTokens.find(function(
29- // suggestionToken
30- // ) {
31- // return suggestionToken.str.indexOf(queryToken.str) === 0;
32- // });
33- // return {
34- // suggestionToken: firstMatchedSuggestionToken,
35- // queryToken: queryToken
36- // };
37- // });
38-
3932 const deDupedTermMatches = termMatches ;
4033
41- // const deDupedTermMatches = termMatches.filter(function(termMatch, index) {
42- // const prevMatches = termMatches.slice(0, index);
43-
44- // const tokenHasAlreadyBeenUsed = prevMatches.some(function(prevMatch) {
45- // return prevMatch.suggestionToken === termMatch.suggestionToken;
46- // });
47-
48- // return !tokenHasAlreadyBeenUsed;
49- // });
50-
5134 // Only consider term matches if we match *every* token in the query
5235 return deDupedTermMatches . every ( function ( match ) {
5336 return ! ! match . suggestionToken ;
0 commit comments