0: xx rights 1: xx rights 2:xx rights 3:xx rights

Function toDecimalism(code = 0) {return parseInt(code, 36)}Copy the code
Code function getBasicAuthCode(code) {return toDecimalism(code).toString(2).split('').reverse() .reduce((arr,e,i) => { if (e === "1") arr.push(i) return arr }, []) }Copy the code
/ / access code function assembleAuthCode (arr) {return arr. Reduce ((sum, e) = > (sum | = 1 < < (e)), 0). The toString (36)}Copy the code
Function hasPermission(code, verificationCode) {return (toDecimalism(code) & (1 << verificationCode)) > 0}Copy the code
console.log(assembleAuthCode([0, 1, 3, 4, 5]))  // 1n
console.log(hasPermission('1n', 0))  // true
console.log(getBasicAuthCode('1n'))  // [0, 1, 3, 4, 5]

Copy the code

Feel interesting trouble dot 👍