In my React program, suppose I had the following dictionary / object
const myDict = {
"a":"Value 1",
"b":"Value 2",
"hello":"Value 3",
"Bye":"Value 4"
}
(note that no keys have values existing in any other keys - For example, no key can contain the a
letter since that is a different key)
And I will be receiving a string that will ONLY CONSIST OF PERMUTATIONS OF THE KEYS TO THIS OBJECT, so, for example, possible string entries will be:
- "abhellob"
- "ababByeahello"
- "ByehelloByeba"
- etc.
And I am looking to create a function that will break the input string down into its constituent parts based upon the keys of myDict
.
So, for example,
"abhellob"
would become["a", "b", "hello", "b"]
How can I create such a function? I've tried, but am getting lost with having to deal with different length keys to myDict
and I don't know how to do it.