0 of 6 problems solved0%
4 of 6

Normalize Names

Accept unknown and produce a clean string[]. If input is a single string, split it by commas. If it is an array, keep items that are strings. Trim spaces.

This is a common pattern when normalizing user input.

function toList(x: unknown) {
  if (typeof x === "string") return x.split(",");
  return Array.isArray(x) ? x : [];
}

Your Task

Create a function that normalizes names into an array of trimmed strings.

  • Implement normalizeNames(input: unknown): string[].
  • If input is a string, split by ',', trim items, and drop empty results.
  • If input is an array, keep items that are strings, trim them, and drop empties.
  • For anything else, return an empty array [].
  • Do not mutate inputs.