Filtered product list (derived state)

A code exercise of about 15 minutes: read the statement, solve «Filtered product list (derived state)» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

On a React catalogue page the state is { query, category, sort } and the visible list is computed from the products, not kept in another state. Write visibleProducts(products, view): filter by category (unless it is "all"), by query (contained in name, case-insensitive, ignoring surrounding spaces) and sort by sort: "price-asc", "price-desc" or "name". Don't mutate the array you receive.