cf.completefrontend

Write the codeEasy

Write classNames(...args) to build a CSS class string from strings, objects, and arrays.

Strings and numbers are added as they are. For an object, each key is added when its value is truthy. Arrays are handled recursively. Falsy arguments (false, null, undefined, 0, "") and true are ignored. Join the classes with single spaces.

Write this
function classNames(...args) {
  // your code
}
 
// classNames("btn", { active: true, disabled: false }, ["lg", null]); // "btn active lg"

Solve it in the editor, with tests

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…