I have various string comparison and diff algorithms, but at some point, before I apply them I want to find if two strings have at least one character in common. This way I will be able to skip more complex functions. So I need a very fast function in JavaScript that will find if string A and string B has at least one common character.
First I was thinking to create a character map for a string A, and then check every character in a string B against that map until something is found. But then I realized that if both strings are huge and they have a common first character, this will be inefficient to create a full map for string A.
UPDATE: someone answered with using indexOf(), this confuses me. Maybe the phrase "have character in common" means the same as "string is a substring of another"? Let me give an example of what I want:
For example JavaScript
and Stop and stay
have a character S
in common. Other example would be please look right
and break the ice
they have a character k
in common.