Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job putting together a comprehensive suite of tests for the reduce method! You've covered many important edge cases. However, there's a critical issue that needs to be addressed. Your tests are currently calling the native Array.prototype.reduce method instead of your custom implementation. In your beforeAll block, you correctly attached your function to Array.prototype.reduce2, but the tests themselves still use .reduce(). To fix this, please update all your test cases to call .reduce2() on the arrays. For example, change arr.reduce(...) to arr.reduce2(...). Once you make this change, your tests will correctly validate your own code.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job updating your tests to use the custom .reduce2() method! The current tests are solid for cases where an initial value is provided.
However, this requires changes because the test suite is missing coverage for a crucial scenario: when reduce is called without an initial value. This is a core part of the function's behavior and changes how the accumulator is initialized and how empty arrays are handled.
To ensure your implementation is fully robust, please add tests to cover these specific cases:
- A standard reduction on an array like
[1, 2, 3]. - The behavior with a single-element array.
- An empty array
[], which should throw aTypeError.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| it('should not call callback for empty array', () => { | ||
| const cb = jest.fn(); | ||
|
|
||
| const result = [].reduce2(cb, 100); | ||
|
|
||
| expect(cb).not.toHaveBeenCalled(); | ||
| expect(result).toBe(100); | ||
| }); |
There was a problem hiding this comment.
This is a great set of tests for cases where an initial value is provided. However, a key part of reduce's functionality is how it behaves when no initial value is given.
Could you add test cases for that scenario? Specifically, you should test:
- A standard array like
[1, 2, 3]. - An array with a single element (the callback shouldn't be called).
- An empty array (this should throw a
TypeError).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent progress on this task! You've done a great job adding tests for using reduce without an initial value, which was the main feedback from last time.
I am approving this submission as an educational override to keep you moving forward, but there is one important fix to make. In src/reduce.test.js, the test should throw TypeError when reducing empty array without initial value is currently skipped. This is a critical requirement for handling edge cases correctly.
Please be sure to remove the .skip from that test to ensure your function is fully compliant. You're very close to a perfect solution!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| expect(Array.isArray(result)).toBe(true); | ||
| }); | ||
|
|
||
| it.skip('should throw TypeError when reducing empty array without initial value', () => { |
There was a problem hiding this comment.
This test is skipped using it.skip, which means it isn't running. According to the requirements, you need to verify that calling reduce on an empty array without an initial value throws a TypeError. Please remove .skip to enable this important test case.
No description provided.