คำอธิบายโจทย์
เขียน function solution(rules, requests) ข้อมูลเข้าและผลลัพธ์เป็นค่า JSON ห้ามแก้ไขอาร์เรย์หรือออบเจ็กต์ข้อมูลเข้า ไม่รองรับไลบรารีภายนอก เครือข่าย หรือฟังก์ชันแบบอะซิงโครนัส rules:{effect,subject,action,resource}[]; requests:{subject,action,resource}[]. A rule matches when each field is '*' or an exact case-sensitive match. Any matching 'deny' overrides every allow. Otherwise allow if a matching 'allow' exists, deny by default. Ignore other effects. Rule order does not matter. Return booleans in request order. ขอบเขตข้อมูล: อาร์เรย์อินพุตแต่ละชุดมีไม่เกิน 50,000 รายการ สตริงไม่เกิน 1,000 ตัวอักษร ตัวเลขต้องเป็นค่าจำกัด จำนวนเต็มและผลรวมจำนวนเต็มอยู่ในช่วงจำนวนเต็มที่ปลอดภัยของ JavaScript ชนิดและความถูกต้องอื่นเป็นไปตามกฎด้านบน
ตัวอย่างข้อมูลเข้าและผลลัพธ์
ตัวอย่าง 1
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"effect": "allow",
"subject": "alice",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
},
{
"subject": "bob",
"action": "read",
"resource": "file"
}
]
]ค่าที่ส่งคืน
[ true, false ]
ตัวอย่าง 2
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"effect": "allow",
"subject": "*",
"action": "*",
"resource": "*"
},
{
"effect": "deny",
"subject": "alice",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
},
{
"subject": "bob",
"action": "read",
"resource": "file"
}
]
]ค่าที่ส่งคืน
[ false, true ]
ตัวอย่าง 3
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"effect": "deny",
"subject": "bob",
"action": "*",
"resource": "*"
},
{
"effect": "allow",
"subject": "*",
"action": "*",
"resource": "*"
}
],
[
{
"subject": "alice",
"action": "read",
"resource": "file"
}
]
]ค่าที่ส่งคืน
[ true ]