Answer the question
In order to leave comments, you need to log in
Another way to compare 2 arrays and return true/false?
There are two arrays containing values. We need to compare whether another array contains at least one value from another array and return true or false.
Is there another more elegant way without iteration, creating an intermediate array and two checks?
const userRoles = ['user', 'admin']
const allowedRoles = ['vasya', 'admin']
function roles(...roles) {
let allowed = roles.map(role => {
return userRoles.includes(role)
})
if (allowed.includes(true)) {
//
} else {
//
}
}
roles(allowedRoles)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question