[5kyu][functionl-programming][math] A Chain adding function

https://www.codewars.com/kata/539a0e4d85e3425cb0000a88/solutions/typescript

We want to create a function that will add numbers together when called
in succession.
This commit is contained in:
2024-10-03 13:56:51 +03:00
parent aeb641e339
commit ffa87ec3a3
+12
View File
@@ -0,0 +1,12 @@
// We want to create a function that will add numbers together when called in succession.
export default function add(x: number): any {
const fn = (y: number) => add(x + y);
fn.valueOf = () => x;
return fn;
}
const seven = add(1)(2)(4);
console.log(seven == 7, 'expect 7')
console.log(+add(1)(2), 'expect 3')