Code Lab

Sum step by step

EasyTypeScript types5 min

Write a function sum that is called three times in a row, sum(a)(b)(c). Each call gets a number, and the last one returns the sum of the three numbers.

Every step must be typed, with no any. Do not change the code at the bottom, each line after @ts-expect-error must stay a type error.

Examples

sum(1)(2)(3)

Returns 6

1 + 2 + 3 is 6.
(() => { const plusFive = sum(2)(3); return [plusFive(1), plusFive(10)]; })()

Returns [ 6, 15 ]

The function from the middle step can be called many times.

Source

Function
Loading the editor...
  1. sum(1)(2)(3) is 6
  2. sum(10)(0)(-4) is 6

Hidden tests run on Submit.