The two strings don’t have to be the same words. If an array has the two strings “monkey” and “money”, the function will return true because deep inside the soul of the word “monkey”, there is the word “money”. Does this mean all monkeys have money? No. It means…. well the function works.
Sometimes words have a hard time finding out who they are. They seek to find as many words within themselves. It is as if the word “monkey” looked into a mirror and instead of finding the word “monkey”, it also found the words “key”, “money”, “monk”, “one”.
Not all words are as lucky as the word “monkey”. One unlucky word is the word “bag”. Now the second string doesn’t have to be an actual word but come on, “ba” and “ag” don’t sound like exciting words. “Ba” is just the sound tired sheep make and “ag” is the sound well … more tired sheep make.
For this function let’s imagine one of the inputs is an array that holds two strings, “hello” and “heefs” (yes, heefs).
If you compared the two words, they look like two different words. That is because they are (I congratulate your eyes). The next step is to know if every letter in “heefs” (the e’s must also appear twice) appear in “hello”.
The word “hello” is is broken down into individual letters and each letter. The only way to know if Mr. Heefs fits in is if every letter in “heefs” is in “hello”, is if he sees himself in the word. Like a mirror, he doesn’t see himself. The second e is missing and there isn’t an f and where is sweet letter s. He stands in confusion with a giant bold question mark written in 45px helvetica bold.
But what if, instead of “heefs” that vocabulary is another “hello”?
Since each letter in “hello” exists inside of … “hello”. The function will return true. Because not all of the letters in “heefs” didn’t exist in the word “hello”, the function would have returned false. Now when the Mr. Hello (previously Mr. Heefs) looks into that mirror, he can finally see himself in the word.
Oh and by the way, the author of the book “Who are you? Who am I?” in the beginning of this post is in fact Mr. Heefs. The book will be soon released to your local imaginary bookstore nearest to your thoughts.