Skip to content

Instantly share code, notes, and snippets.

@Robert-Fairley
Last active January 15, 2020 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robert-Fairley/98a2da3f0361e524f4e056d947a6172a to your computer and use it in GitHub Desktop.
Save Robert-Fairley/98a2da3f0361e524f4e056d947a6172a to your computer and use it in GitHub Desktop.
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;
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 };
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