Your question is Validate JavaScript Riddle Assertions. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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).
true/false appear only as the output of isPalindrome(...) or as literals on the right/left."2" is not equal to 2.