Skip to main content

Practice ยท 3 of 3

Exhaustive Switch

Write describeShape(v) where v is null | string | number | boolean | array. RETURN: "nothing" for null, "text" for strings, "number" for numbers, "flag" for booleans, "list of N" (with the length) for arrays, and for ANYTHING ELSE throw new Error("Unhandled shape") โ€” the runtime twin of the never-check.

Difficulty: intermediate

Back to lesson: Practice: Unions & Narrowing โ€” Practice