I'm puzzled as to why my array.map function is returning undefined, but my for loop is returning the result. When I console log map, it displays:
Tom Dick Harry
and when I console log the for loop, it shows:
['Tom', 'Dick', 'Harry']
I'm unsure if this issue is related to showing undefined.
var friends = ["Tom", "Dick", "Harry"];
var secondLevelFriends = ["Anne", "Harry", "Quinton"];
var allUsers = ["Tom", "Dick", "Harry", "Anne", "Quinton", "Katie", "Mary"];
function findPotentialFriends(existingFriends) {
return function(x) {
// existingFriends.map(function(elem) {
// if(elem === x) return false;
// else return true;
// })
for(var i = 0; i < existingFriends.length; i++) {
if(existingFriends[i] === x) return false;
else return true;
}
}
}
var isNotAFriend = findPotentialFriends( friends );
isNotAFriend(allUsers[0]); // false