Last active
January 15, 2020 21:31
-
-
Save Robert-Fairley/98a2da3f0361e524f4e056d947a6172a to your computer and use it in GitHub Desktop.
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
export declare function add(a: number, b: number): number; | |
export declare function add(a: number, b: number, c: number): number; | |
export declare function add(a: number, b: number, c: number, d: number): number; |
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
function add() { | |
switch (arguments.length) { | |
case 2: | |
return arguments[0] + arguments[1]; | |
case 3: | |
return arguments[0] + arguments[1] + arguments[2]; | |
case 4: | |
return arguments[0] + arguments[1] + arguments[2] + arguments[3]; | |
default: | |
throw new Error("Too few or too many arguments. Number of arguments: " + arguments.length); | |
} | |
} | |
module.exports = { add }; |
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
import { add } from "./add"; | |
console.log("4 + 4 =", add(4,4)); | |
console.log("4 + 4 + 4 =", add(4,4,4)); | |
console.log("4 + 4 + 4 + 4 =", add(4,4,4,4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment