From ffa87ec3a365e79e48524e63802742b4668f30cf Mon Sep 17 00:00:00 2001 From: Vasily Guzov Date: Thu, 3 Oct 2024 13:56:51 +0300 Subject: [PATCH] [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. --- lib/cheinAddFun.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/cheinAddFun.ts diff --git a/lib/cheinAddFun.ts b/lib/cheinAddFun.ts new file mode 100644 index 0000000..af56a8f --- /dev/null +++ b/lib/cheinAddFun.ts @@ -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')