Skip to content
Snippets Groups Projects
Commit 43d8fac2 authored by CORONA Nikola's avatar CORONA Nikola
Browse files

TD5 Exercice 2

parent e989c8c9
No related branches found
No related tags found
No related merge requests found
......@@ -11,3 +11,6 @@ Deno.test("multiplication par 0", () => {
Deno.test("multiplication par un nombre négatif", () => {
assertEquals(multAdd(3, -8), -24);
});
Deno.test("multiplication par 2 nombre négatif", () => {
assertEquals(multAdd(-8, -8), 64);
});
export function multAdd(x: number, y: number): number {
let resultat = 0;
let inf = 0;
if (y < 0){
y = -y
inf = 1 ;
}
for (let i = 0; i < y; i++) {
resultat += x;
}
return resultat;
}
\ No newline at end of file
if (inf === 1 ) return -resultat ;
else return resultat;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment