From 13a8b089e2355819add5bb06b6cb73a5fc27e50c Mon Sep 17 00:00:00 2001 From: Tony Le Date: Wed, 27 Nov 2024 16:12:38 -0500 Subject: [PATCH] Sum 0 test --- flag1/mafs.js | 1 + flag1/mafs.test.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/flag1/mafs.js b/flag1/mafs.js index 51c234a..819ce1b 100644 --- a/flag1/mafs.js +++ b/flag1/mafs.js @@ -19,6 +19,7 @@ function divide(a, b) { } function sum(...args) { + if (args.length === 0) return 0; return args.reduce((acc, curr) => acc + curr, 0); } diff --git a/flag1/mafs.test.js b/flag1/mafs.test.js index a7179d5..fbd16a0 100644 --- a/flag1/mafs.test.js +++ b/flag1/mafs.test.js @@ -23,3 +23,7 @@ test('divides 8 / 2 to equal 4', () => { test('sums 1 + 2 + 3 + 4 to equal 10', () => { expect(sum(1, 2, 3, 4)).toBe(10); }); + +test('sums 1 + 2 + 3 + 4 to equal 10', () => { + expect(sum()).toBe(0); +});