Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let bobsFollowers = ['Mary', 'Jane', 'Tim', 'John'];
- let tinasFollowers = ['John', 'Mary', 'Sam'];
- let mutualFollowers = [];
- for (let i =0; i < bobsFollowers.length; i++){
- for (let j =0; j < tinasFollowers.length; j++){ //note the use of different variable name j
- if (bobsFollowers[i] === tinasFollowers[j]){
- mutualFollowers.push(bobsFollowers[i]); //i is the index(number) hence it should be push bobsFollowers[i] to push the value
- }
- }
- }
- console.log(mutualFollowers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement