During my iteration through both arrays, I am successfully passing most of the tests. However, there is one test that presents a challenge as it continues to nest the loop against the first loop even after the matched element has been removed.
Input: s1: "abca" s2: "xyzbac"
This is the code snippet I have been working with:
function commonCharacterCount(s1, s2) {
const arrayOne = s1.split("")
const arrayTwo = s2.split("")
var matches = [];
for (let i = 0; i < arrayOne.length; i++) {
for (let j = 0; j < arrayTwo.length; j++) {
console.log(arrayTwo[j],arrayOne[i], matches)
if (arrayOne[i] === arrayTwo[j]) {
matches.push(arrayOne[i])
arrayOne.splice(arrayOne[i], 1)
}
}
}
return matches.length
}
Upon inspecting the console log for test 3, which happens to be failing, I noticed an issue where it skips over the second item "b".