← Back to problems
Frontend: Accordion Component (Single vs Multi Open)
MediumTypeScriptDescription
> This problem is paper-only - see explanation for the canonical React solution.
Build an Accordion component with N panels. A `mode` prop controls behavior:
- `"single"`: at most one panel open at a time. Toggling an open panel closes it.
- `"multi"`: any combination of panels can be open.
**For the auto-grader:** implement `accordionReducer(openIds, toggleId, mode)` returning the new `openIds` set as a sorted array. Input `openIds` is a sorted array.
Example 1
Input: openIds = ["a"], toggleId = "b", mode = "single"
Output: ["b"]
Example 2
Input: openIds = ["a"], toggleId = "b", mode = "multi"
Output: ["a","b"]
Example 3
Input: openIds = ["a"], toggleId = "a", mode = "single"
Output: []
Constraints
- mode is "single" | "multi"
- All ids are non-empty strings.
Loading editor...