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 [].
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.
Input: parts = [["card"],["flat"]] Output: ["card-flat"]
Each group has one option, so there is one name.
1 <= parts.length <= 60 <= parts[i].length <= 4-.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).
I'm here to help with #286 Variant Class Names. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.