I am trying to find common strings in given two strings.
Example:
string1 = "mega,cloud,two,website,final"
string2 = "window,penguin,literature,network,fun,cloud,final,sausage"
answer = "cloud,final,two"
So far this is what i got:
function commonWords(first, second) {
var words = first.match(/\w+/g);
var result = "";
words.sort();
for(var i = 0; i < words.length; i++){
if(second.includes(words[i])){
result = result.concat(words[i]);
result += ",";
}
}
result = result.substr(0, result.length -1);
return result;
}
But the result that i got is :
answer = cloud,final
Can you help me out please? First time asking question on StackOverFlow, so sorry for the typing.
twowhen there is notwostring in second string