Currently, I'm facing an issue with my code where it is returning false instead of true:
function checkValidUsers(validUsers)
{
var validIds = validUsers.map(function (user) { return user.id; });
return function (users)
{
var ids = users.map(function (user) { return user.id; });
return ids.every(function (id) { return id in validIds; } );
}
}
var check = checkValidUsers([{ id: 1 }, { id: 2 }, { id: 3 }]);
check([{ id: 2 }, { id: 3 }]); // returns false
Upon examining the map functions, they are correctly generating arrays ([1,2,3] for the first and [2,3] for the second). However, it seems that the issue lies within the every function.
I am seeking assistance to identify and resolve the bug in this code. Can anyone provide insights?