Question presented to candidate: "We have a product catalogue in memory. Build the listing page: a grid of products with a filter sidebar (category checkboxes, a price range, a minimum rating and an in-stock toggle) and a sort dropdown. Next to each filter option, show how many products you would get if you picked it. Show the active filters as removable chips, the result count, and a helpful empty state. A shared link should open the same filtered view."
Requirements:
- Facets: categories (multi-select, OR within the facet), min and max price (validated), minimum rating (radio), in stock only; facets combine with AND.
- Sort: most popular, price low to high, price high to low, top rated; ties keep catalogue order.
- Live facet counts that answer "what would I get if I picked this option", given every other active filter.
- Active filter chips with remove buttons, "Clear all" (which keeps the chosen sort), a result count announced to screen readers, and an empty state with a clear action.
- URL sync with
history.replaceState(?cat=Audio,Cameras&min=100&rating=4&stock=1&sort=price-asc), parsed and validated on load. - Responsive: sidebar beside the grid on desktop, stacked above it on a phone.
What a strong answer should cover:
- A single filter state object as the source of truth; results, counts, chips and the price error are all derived from it.
- A composable filter pipeline: one predicate per facet, combined with AND, so adding a facet is one line.
- Disjunctive facet counts: each facet's counts apply every filter except that facet's own, otherwise selecting "Audio" would show 0 for every other category.
- Memoising the derivation, and an honest note about when that matters (thousands of products, or server-side search).
- Validation of user input (min above max, negative numbers) without throwing away what the user typed.
- Accessibility:
fieldsetandlegendper facet, labelled inputs, chip buttons with "Remove filter" labels, anaria-livecount.
Clarifying questions expected:
- "Is filtering done in the browser over the whole catalogue, or by an API with pagination?"
- "Within one facet, is it OR (Audio or Cameras) and across facets AND?"
- "Should the URL push history entries so Back undoes a filter, or replace them?"
Code / implementation expected: Yes. A working page in React, Vue or Angular with the filter logic in plain functions, facet counts, chips, sorting and URL sync, over an in-file product list.