Apologize if this has been answered already (I didn’t see the question asked yet)
why does this work?
const bobsFollowers = ['Jim', 'Joe', 'Jerry', 'John'];
const tinasFollowers =['Jessica','Jim', 'Joe'];
const mutualFollowers = [];
for (let i = 0; i < bobsFollowers.length; i++) {
for (let j = 0; j < tinasFollowers.length; j++) {
if (bobsFollowers[i] === tinasFollowers[j]) {
mutualFollowers.push(bobsFollowers[i]);
}
}
}
console.log(mutualFollowers)
It seems to me that the array would never match the names as the indexes are off by 1 (Jim is index 0 in bob’s array and index 1 in tina’s) When index 0 for bob’s array is called, it gets Jim, when index 0 is called for tina’s, it gets Jessica… How would these ever equal each other? Very likely I misunderstanding some concept…
thanks in advance.