From 0ee98654a397b407fd7559b49c3f5776e48999c6 Mon Sep 17 00:00:00 2001 From: MALLINGER Robin <robin.mallinger1@etu.univ-lorraine.fr> Date: Mon, 31 Mar 2025 09:57:55 +0200 Subject: [PATCH] refresh --- exo7.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/exo7.ts b/exo7.ts index e69de29..23da63b 100644 --- a/exo7.ts +++ b/exo7.ts @@ -0,0 +1,28 @@ +function multiply(x: number, y: number): number { + + if (y < 0) { + x = -x; + y = -y; + } + + let result = 0; + + for (let i = 0; i < y; i++) { + result += x; + } + return result; +} + + +function testMultiply() { + const testCases = [ + [0, 0], [5, 3], [3, 5], [-5, -2], [-2, -5], + [-74, 2], [-1, 75], [10, -25], [10, -3] + ]; + + for (const [x, y] of testCases) { + console.log(`multiply(${x}, ${y}) = ${multiply(x, y)}`); + } +} + +testMultiply(); \ No newline at end of file -- GitLab