Helper Functions#
add(x, y)#
import { assertEquals } from "/deps.ts";
import { add } from "./add.ts";
Deno.test("add()", async (t) => {
await t.step("should add any two numbers", () => {
assertEquals(add(0, 0), 0);
assertEquals(add(0, -0), 0);
assertEquals(add(1.7, -4), -2.3);
assertEquals(add(-1e3, -1), -1001);
});
});
/**
* Adds `x` and `y`.
*
* **TIME COMPLEXITY**: O(1). `x` and `y` are simply added once.
*
* **SPACE COMPLEXITY**: O(1). No extra space is required by this
* algorithm to add the two numbers.
*
* @param x
* @param y
* @returns The value of `x` and `y` added together.
*/
function add(x: number, y: number): number {
return x + y;
}
export { add };