0 of 6 problems solved0%
3 of 6

Normalize Email

Optional properties can be missing. Sometimes a field is present but set to null. Treat both as “no value.” When a string is present, you can clean it up.

const raw: string | null | undefined = " [email protected] ";
const cleaned = raw?.trim().toLowerCase();

Return a new object when you make changes so callers keep their old data if needed.

Your Task

Make a new user object with a normalized email field.

  • Define interface User { name: string; email?: string | null }.
  • Write function normalizeEmail(u: User): User.
  • If email is a string, set it to email.trim().toLowerCase(); if the trimmed value is '', treat it as missing.
  • If email is null or undefined, leave it missing.
  • Return a new object; do not mutate the input.