Codington
0 of 6 problems solved0%

Overloaded Parse Number

Overloads allow one function to accept different input shapes and return different output types. You write multiple signatures, then a single implementation that handles both.

Parse a single string to a number, or an array of strings to an array of numbers. Use Number or parseFloat and keep the logic small.

function len(x: string): number; function len(xs: string[]): number[]; function len(x: string | string[]) { return Array.isArray(x) ? x.map((s) => s.length) : x.length; }

Your Task

Create an overloaded parseNumber that handles a string or an array of strings.

  • Write two overload signatures:
  • parseNumber(s: string): number
  • parseNumber(arr: string[]): number[]
  • Provide one implementation that handles both inputs.
  • Use parseFloat and return NaN for non-numeric pieces.
  • Do not mutate the input array.