I am facing a challenge with identifying three added characters in the second string that are not present in the first string. These added characters could be located anywhere within the string.
For example:
string1 = "hello"
string2 = "aaahello"
// => 'a'
The added characters may also overlap with existing characters in the original string, as shown below:
string1 = "abcde"
string2 = "2db2a2ec"
// => '2'
In another scenario:
string1 = "aabbcc"
string2 = "aacccbbcc"
// => 'c'
I have attempted to address this issue using the following function, but it does not accurately pinpoint the three identical added characters in the second string:
function addedChar(a, b){
var i = 0;
var j = 0;
var result = "";
while (j < b.length)
{
if (a[i] != b[j] || i == a.length)
result += b[j];
else
i++;
j++;
}
return result;
}