There is an object, which represents the role of an user:
const user = {
isEditor: false,
isAdmin: true,
isTranslator: false
}
I need to pass some elements to a function an check if any of this role has a true value in the user object.
result = hasPermission(user, ['editor', 'admin']) // true
result = hasPermission(user, ['editor', 'translator']) // false
I've some problems with that, as the roles are named a bit differently.
I thought also about using _.some() as I need to check for only one true value.
function hasPermission (user, roles) {
roles.forEach(role => {
user[role] // is not working as user keys named differently
})
}
return user["is" + "admin".slice(0,1).toUpperCase() + "admin".slice(1)];