From d00c2d5f7bb987d90f9ad841d9285b52da69ed1c Mon Sep 17 00:00:00 2001 From: Eduard Nerkararian Date: Wed, 4 Jun 2025 22:04:07 +0300 Subject: [PATCH] Solution --- src/reduce.test.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/reduce.test.js b/src/reduce.test.js index 47a892f..9a39e69 100644 --- a/src/reduce.test.js +++ b/src/reduce.test.js @@ -11,9 +11,41 @@ describe('reduce', () => { delete Array.prototype.reduce2; }); - it('should ', () => { + it('should sum numbers with initial value', () => { + const result = [1, 2, 3, 4].reduce2( + (acc, val) => acc + val, + 0 + ); + expect(result).toBe(10); }); - // Add tests here + it('should multiply numbers with initial value', () => { + const result = [2, 3, 4].reduce2( + (acc, val) => acc * val, + 1 + ); + + expect(result).toBe(24); + }); + + it('should reduce correctly without an initial value', () => { + const result = [1, 2, 3].reduce2( + (acc, val) => acc + val + ); + + expect(result).toBe(6); + }); + + it('should handle single-element array without initial value', () => { + const result = [5].reduce2((acc, val) => acc + val); + + expect(result).toBe(5); + }); + + it('should handle empty array with initial value', () => { + const result = [].reduce2((acc, val) => acc + val, 100); + + expect(result).toBe(100); + }); });