Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/reduce.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});