Here is my code:
I want to iterate through each pair of elements of the arrays, and if the strings in each pair contain one or more common substrings, console.log(true), otherwise console.log(false).
So, output should be true, false, because "first" and "criss" have common substrings ("r", "i", "s")
Here is my code for now;
const a = ["first", "hi"];
const b = ["criss", "student"];
function commonSubstring(a, b) {
a.forEach(a1 =>
b.forEach(a2 => {
for (i = 0; i < a1.length; i++) {
if (a1.charAt(i) == a2.charAt(i)) {
console.log(true");
}
}
})
);
}
commonSubstring(a, b);
Thanks for answers in advance!
if (a1.charAt(i) == a2.charAt(i)), so the only thing “first” and “criss” have in common would be the “s” at position 4 (3, if you start counting at 0.)