I am not sure why my array.map function returns undefined but my for loop returns the result. When I console log map it displays:
Tom Dick Harry
and when console log for loop it shows
['Tom', 'Dick', 'Harry']
Not sure if this is the problem of showing undefiend.
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