Description

In web development, we often need to dynamically generate a list of CSS class names. The classNames utility helps combine strings, numbers, arrays, and objects into a single string of class names.

Your function should:

  • Skip falsy values like null, undefined, false, 0, or "".
  • Accept strings and numbers and add them directly.
  • Flatten arrays recursively, including nested arrays.
  • Handle objects, including the key in the output only if its value is truthy.

This is similar to popular libraries like classnames and is widely used in React projects.

Your Task

Write a function classNames(...args) that:

  1. Takes any number of arguments.
  2. Processes strings, numbers, arrays, and objects as described.
  3. Returns a single string of class names separated by spaces.

Example

Input

classNames("btn", "btn-primary", 123);

Output

"btn btn-primary 123"

Additional Examples

classNames("btn", null, "btn-primary", ["active", ["large"]])
// Output: "btn btn-primary active large"

classNames("btn", { "btn-primary": true, "btn-secondary": false })
// Output: "btn btn-primary"

classNames([
"btn",
{ "btn-primary": true, "btn-secondary": false },
["large", { "text-center": true }]
])
// Output: "btn btn-primary large text-center"

classNames(null, undefined, "", false, 0, "class1", ["class2", { class3: true }])
// Output: "class1 class2 class3"