You’re building an internal hiring platform for a fintech company that screens JavaScript candidates at scale (hundreds of thousands of submissions per day). To reduce fraud and keep grading deterministic, the platform runs “vanilla JS riddles” inside a locked-down test framework. Each riddle is a tiny assertion like expect(reverse("abc")).toBe("cba").
Your job is to implement the core assertion evaluator that determines whether each riddle passes without executing JavaScript. Instead, you’ll parse and evaluate a limited, safe subset of expressions.
Implement evaluate_riddles(riddles: list[str]) -> list[bool].
Each riddle string has the form:
expect(<expr>).toBe(<expr>)
Where <expr> is one of:
"abc"0, 12, 300reverse(<expr>), len(<expr>), or isPalindrome(<expr>)Supported functions:
reverse(s): returns the reversed stringlen(s): returns the length of the stringisPalindrome(s): returns true if s equals its reverse, else falseReturn a boolean per riddle indicating whether the left and right expressions evaluate to the same value (type-sensitive: string vs int vs bool).
Example 1
riddles = ["expect(reverse(\"abc\")).toBe(\"cba\")"][true]reverse("abc") evaluates to "cba", which equals the right-hand string.Example 2
riddles = ["expect(len(reverse(\"ab\"))).toBe(2)", "expect(isPalindrome(\"aba\")).toBe(true)"][true, true]reverse("ab") -> "ba", len("ba") -> 2. Also, "aba" is a palindrome.1 <= riddles.length <= 10^4<= 200[a-z] (no escapes besides the surrounding quotes in the input representation)true/false appear only as the output of isPalindrome(...) or as literals on the right/left."2" is not equal to 2.