0 of 6 problems solved0%
4 of 6

Map or Apply Overload

A single function can work on both one value and an array of values. Overloads let the return type match the input shape. Keep one implementation using a small Array.isArray check.

You will transform numbers with a provided function.

function inc(n: number) {
  return n + 1;
}

Your Task

Create an overloaded applyOrMap that applies a transform to a number or an array of numbers.

  • Write overloads:
  • (fn: (n: number) => number, x: number): number
  • (fn: (n: number) => number, x: number[]): number[]
  • Implement once using Array.isArray.
  • Do not mutate the array.
  • Keep runtime small.