Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Search Filter

Derived Statemedium

Course · Section 11: Working With Arrays · Lecture 160: The reduce Method

Implement `filterSearch(items, query)` returning items whose `name` contains `query`, case-insensitive.

Sample tests

Input: filterSearch([{"name":"Apple"},{"name":"Banana"}], "an")
Output: [{"name":"Banana"}]
Input: filterSearch([{"name":"Apple"}], "")
Output: [{"name":"Apple"}]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Case-sensitive comparison missing obvious matches.
  • Recomputing inside a child when it could be memoized for large lists.

Learning resources

  • React: Choosing the State Structure
Approach & explanation (try first)

Normalizing case and using includes gives a forgiving search filter, the typical derived list behind a search box.

Loading...
⌘/Ctrl + Enter

Run your code to see results.