Drill

ProblemsJavaScript › patterns

Does this account hold every right

easypatternsBit manipulationJavaScript

Access control packs rights into a bitfield. A guard checks whether an account holds all of the rights an action needs.

holdsEveryRight(held: int, needed: int) → bool

Solve it in the editor →

Where you start

function holdsEveryRight(held, needed) {
  
}

Worked examples

CallResult
holdsEveryRight(7, 5)true
holdsEveryRight(5, 7)false
holdsEveryRight(0, 0)true
holdsEveryRight(8, 0)true

Hint

Mask what is held against what is needed. If the masked result still equals what was needed, nothing was missing.

Reference solution in JavaScript
function holdsEveryRight(held, needed) {
  return (held & needed) === needed;
}

The same problem in another language

More patterns problems in JavaScript