Skip to the code
cf.
+10 XP

#286 Variant Class Names

easy

A design system builds CSS class names from parts. parts is a list of groups, and each group is a list of options, such as [["btn"], ["sm", "lg"], ["primary", "ghost"]].

A class name takes exactly one option from every group, in group order, joined with -. Write variantClassNames(parts) that returns every class name.

Order the names so that earlier groups change slowest: all names with the first option of group 0 come first, and within those, all names with the first option of group 1 come first, and so on. If any group is empty, no name can be built, so return [].

Example 1

Input: parts = [["btn"],["sm","lg"],["primary","ghost"]]
Output: ["btn-sm-primary","btn-sm-ghost","btn-lg-primary","btn-lg-ghost"]

sm comes before lg, and for each size both variants are listed before the size changes.

Example 2

Input: parts = [["card"],["flat"]]
Output: ["card-flat"]

Each group has one option, so there is one name.

Constraints

  • 1 <= parts.length <= 6
  • 0 <= parts[i].length <= 4
  • Options are short lowercase strings without -.
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).