Check this Hashtable implementation
How do I implement a Dictionary or Hashtable in Javascript?[
^]
The pseudo algorithm could look like this
function IdentifyCommonString(string srcString1, string srcString2)
{
var hashTable = new HashTable();
var sourceArray1 = srcString1.split(",");
var sourceArray2 = srcString2.split(",");
var arrayLength = sourceArray1.length;
for (var i = 0; i < arrayLength; i++) {
var item = hashTable.get_item(sourceArray1[i]);
if (!item)
hashTable.set_item(item, item);
else {
//our common string has now been identified
alert(item);
}
}
arrayLength = sourceArray2.length;
for (var k = 0; i < arrayLength; k++) {
var item = hashTable.get_item(sourceArray2[i]);
if (!item)
hashTable.set_item(item, item);
else {
//our common string has now been identified
alert(item);
}
}
}