Skip to content

Instantly share code, notes, and snippets.

@willie-hung
Last active August 2, 2023 19:34
Show Gist options
  • Save willie-hung/ce2914b9ea2c4fd6cce4f2c2f3073fef to your computer and use it in GitHub Desktop.
Save willie-hung/ce2914b9ea2c4fd6cce4f2c2f3073fef to your computer and use it in GitHub Desktop.
post_32
export function add(...args: number[]): number {
return args.reduce((a, b) => a + b, 0);
}
// in-source test suites
if (import.meta.vitest) {
const { it, expect } = import.meta.vitest;
it("add", () => {
expect(add()).toBe(0);
expect(add(1)).toBe(1);
expect(add(1, 2, 3, 4, 5)).toBe(15);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment