Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

classNames from Map

Props & Classesmedium

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `classNames(map)` returning a space-separated string of the keys whose values are truthy.

Sample tests

Input: classNames({"active":true,"disabled":false,"big":true})
Output: "active big"
Input: classNames({})
Output: ""

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Including keys with falsy values in the output.
  • Leaving a trailing space from naive concatenation.

Learning resources

  • React: Passing Props to a Component
Approach & explanation (try first)

Filtering object keys by truthy value and joining with spaces builds a className string conditionally, the core of utilities like clsx.

Loading...
⌘/Ctrl + Enter

Run your code to see results.