Duo Security Interview Question

Given two strings as inputs, write a function that returns all the characters the two strings have in common.

Interview Answer

Anonymous

Apr 16, 2019

function FindCommon(sen1, sen2) { let split1 = sen1.split(""); let split2 = sen2.split(""); let match = []; const length = split1.length + split2.length; for(let i = 0; i < length; i++) { if(split1[i] === split2[i]) match.push(split1[i]); } let join = match.join(""); return join; }