Last active
April 25, 2023 20:38
-
-
Save vineckb/0b431cf9879fda023548e169a1302592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const SYNONYMS = [ | |
| ['rate', 'ratings'], | |
| ['approval', 'popularity'], | |
| ]; | |
| const QUERIES = [ | |
| ['obama approval ratings', 'obama popularity rate'], | |
| ['obama approval rates', 'obama popularity ratings'], | |
| ['obama approval rate', 'popularity ratings obama'], | |
| ]; | |
| const isSynonym = (a, b) => | |
| SYNONYMS.reduce((acc, [sA, sB]) => { | |
| if (acc) return acc; | |
| if (a == sA) { | |
| return b == sB; | |
| } | |
| if (b == sA) { | |
| return a == sB; | |
| } | |
| return acc; | |
| }, false); | |
| QUERIES.map(([a, b]) => { | |
| const bList = b.split(' '); | |
| return a | |
| .split(' ') | |
| .map((word, index) => { | |
| if (word === bList[index]) return true; | |
| return isSynonym(word, bList[index]); | |
| }) | |
| .reduce((acc, curr) => acc && curr, true); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment