Last active
February 7, 2020 12:09
-
-
Save OAyomide/5b1246bb0bd79519ee99bf1ef38b9d3b to your computer and use it in GitHub Desktop.
Solution to testRigor AI test
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 criminals = new Map(); | |
| criminals.set("Paul White", "Roger Night, Peter Llong Jr."); | |
| criminals.set("Roger Fedexer", "Rob Ford, Pete Lord, Roger McWire"); | |
| criminals.set("Paul White Jr.", null); | |
| criminals.set("Red Fortress", "Roger Rabbit, Ross Winter"); | |
| criminals.set("Redford Fort", "Red Strong, Red Fort"); | |
| function getCriminal(input) { | |
| const names = [...criminals.keys()] | |
| const aliases = [...criminals.values()] | |
| const inputRegex = new RegExp(input, 'gi') | |
| let nameMatch, aliasesMatch | |
| nameMatch = names.find(n => inputRegex.test(n)) | |
| if (!nameMatch) { | |
| aliasesMatch = aliases.find(n => inputRegex.test(n)) | |
| } | |
| if (nameMatch) { | |
| const aliases = criminals.get(nameMatch) | |
| return `First name: ${nameMatch}. Aliases: ${aliases}` | |
| } else if (aliasesMatch) { | |
| for (let [key, value] of criminals) { | |
| if (value === aliasesMatch) { | |
| return `First name: ${key}. Aliases: ${aliasesMatch}` | |
| } | |
| } | |
| } else { | |
| return `No match` | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment