Created
December 16, 2018 21:18
-
-
Save runandrerun/7f2d0263d5fff6b6a48afbf101351a52 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 dictionaryMatch = (stringA, stringB) => { | |
// create an empty dictionary to store your string | |
const dictionary = {}; | |
// split stringA by character and iterate over it | |
// create a new key value pair in the dictionary | |
// for each unique character within the array | |
stringA.split('').forEach(character => { | |
dictionary[character] = character; | |
}); | |
// perform a lookup in the dictionary: | |
// iterate over stringB, and check to see if the key | |
// exists in the dictionary we just created | |
const bLength = stringB.length; | |
for (let i = 0; i < bLength; i++) { | |
if (dictionary[stringB[i]] === stringB[i]) { | |
return true; | |
} | |
}; | |
// if the key does not exist then return false | |
return false; | |
}; | |
const HELLO = "Hello"; | |
const GOODBYE = "Goodbye"; | |
dictionaryMatch(HELLO, GOODBYE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment