could you please tell me why my script is broken? It is an exercise in a Udemy lesson. You need only returning users who have admin level access
var users = [
{ id: 1, admin: true },
{ id: 2, admin: false },
{ id: 3, admin: false },
{ id: 4, admin: false },
{ id: 5, admin: true },
];
var filteredUsers;
function isAdmin(array, property){
return array.filter(function(key){
return key[property] === 'true';
})
}
filteredUsers = isAdmin(users, 'admin');
Thank you
true !== 'true'isAdminis a "predicate," and should be used as the function inside .filter(). Also, calling it "isAdmin" and giving it the property name is redundant. Shouldn't isAdmin always know it should check the admin property?