Last active
September 6, 2022 18:02
-
-
Save madmax911/480435e38bffa1198cd1996838116d3b to your computer and use it in GitHub Desktop.
An example of unit tests for a currying function. One of the Casidoo challenges.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Currying (cool stuff) | |
function addg(a) { | |
if (a === undefined) return a; | |
return function g(b) { | |
if (b !== undefined) { | |
return addg(a+b); | |
} | |
return a; | |
}; | |
} | |
Unit test for addg: | |
console.assert(addg() === undefined, `addg() === ${addg()}, should be undefined`); | |
console.assert(typeof addg(1) === "function", `typeof addg(1) === ${typeof addg(1)}, should be function`); | |
console.assert(addg(1)(2)() === 3, `addg(1)(2)() === ${addg(1)(2)()}, should be 3`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment