Skip to content

add task solution#97

Open
melarkkkk wants to merge 3 commits intomate-academy:masterfrom
melarkkkk:develop
Open

add task solution#97
melarkkkk wants to merge 3 commits intomate-academy:masterfrom
melarkkkk:develop

Conversation

@melarkkkk
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. A standard reduction on an array like [1, 2, 3].
  2. The behavior with a single-element array.
  3. An empty array [], which should throw a TypeError.

✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +67 to +74
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);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. A standard array like [1, 2, 3].
  2. An array with a single element (the callback shouldn't be called).
  3. An empty array (this should throw a TypeError).

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

expect(Array.isArray(result)).toBe(true);
});

it.skip('should throw TypeError when reducing empty array without initial value', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants