Files
typescript-katas/5kyu/a-chain-adding-function/solution.ts
2025-02-01 23:15:40 +01:00

8 lines
264 B
TypeScript

export default function add(x: number) {
const sum = (y: number): any => add(x + y);
// set .valueOf to return the current sum when the object is coerced to a primitive
// for example, when it is compared to a number
sum.valueOf = () => x;
return sum;
}