Skip to main content
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 61 5151 50 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execute. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(ua|p[u-a&&6a?6-3*G.includes(g))+P]>'Z'+P:P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(ua|p[u-a&&6a?6-3*G.includes(g))+P]>'Z'+P:P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0, [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execute. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0, [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 51 50 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execute. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[u-a?6-3*G.includes(g)+P:P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[u-a?6-3*G.includes(g)+P:P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0, [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

added the new test case
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 61 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for executionexecute. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0,  [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execution. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15, 0,  [0, 1, 2], 1)) // True  (superuser)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execute. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0, [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

saved 10 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 6161 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execution. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|/[a-z]/.test(p[a|p[(u-a&&6-3*G.includes(g))+P])+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|/[a-z]/.test(p[a|p[(u-a&&6-3*G.includes(g))+P])+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15, 0,  [0, 1, 2], 1)) // True  (superuser)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execution. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|/[a-z]/.test(p[(u-a&&6-3*G.includes(g))+P])

###Test cases

let f =

(p,u,g,a,G,P)=>!a|/[a-z]/.test(p[(u-a&&6-3*G.includes(g))+P])

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15, 0,  [0, 1, 2], 1)) // True  (superuser)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

#JavaScript (ES6), 61 51 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execution. Returns 0 or 1.

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

###Test cases

let f =

(p,u,g,a,G,P)=>!a|p[(u-a&&6-3*G.includes(g))+P]>'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15, 0,  [0, 1, 2], 1)) // True  (superuser)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)

Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading