// I believe key here is that both arrays are sorted
function FindIntersection (strArr) {
const inBothStrings = []
const arr1 = strArr[0].split(', ')
const arr2 = strArr[1].split(', ')
let i=0,j=0;
while (i<arr1.length&&j<arr2.length){
//casting to numbers
let a = arr1[i]|0;
let b = arr2[j]|0;
I am a full stack engineer, passionate about solving complex problems and collaborating with driven teams! I have 4+ years of experience working at small to mid sized startups.
// I believe key here is that both arrays are sorted
function FindIntersection (strArr) {
const inBothStrings = []
const arr1 = strArr[0].split(', ')
const arr2 = strArr[1].split(', ')
let i=0,j=0;
while (i<arr1.length&&j<arr2.length){
//casting to numbers
let a = arr1[i]|0;
let b = arr2[j]|0;
if(a==b){
inBothStrings.push(a)
i++;
j++;
}
else if(a>b){
j++;
}
else if(b>a){
i++;
}
}
return inBothStrings.join(',')
}
Bingo! Nice work!