Skip to the code
cf.
+10 XP

#292 Every Filter Chip Selection

easy

A product grid has a row of filter chips, one per tag in tags. A shopper can switch on any mix of chips, including none.

Write allFilterSelections(tags) that returns every possible selection as an array of the tags that are on.

The selections may be in any order, and the tags inside a selection may be in any order. Every selection must appear exactly once.

Example 1

Input: tags = ["sale","new"]
Output: [[],["sale"],["new"],["sale","new"]]

Each chip is on or off, so 2 chips give 2 × 2 = 4 selections, including none.

Example 2

Input: tags = ["red"]
Output: [[],["red"]]

One chip: off or on.

Constraints

  • 0 <= tags.length <= 10
  • All tags are distinct.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).