Skip to content

add task solution#2465

Open
nnovik wants to merge 2 commits intomate-academy:masterfrom
nnovik:develop
Open

add task solution#2465
nnovik wants to merge 2 commits intomate-academy:masterfrom
nnovik:develop

Conversation

@nnovik
Copy link

@nnovik nnovik commented Feb 8, 2026

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

I am requesting changes because a core requirement of the task is not yet met: Array.prototype.sort is not implemented to delegate to your custom sort2, which means the assignment’s main goal isn’t fulfilled. Your sort2 bubble-sort implementation itself looks good: it handles the default string comparator correctly, works in-place, and includes an early-exit optimization, so the foundation is solid.

The critical issue to fix is:

  • After you define [].__proto__.sort2 in src/arrayMethodSort.js, you must also define Array.prototype.sort (or equivalently [].__proto__.sort) so that it calls sort2, for example:
    Array.prototype.sort = function (compareFunction) {
      return this.sort2(compareFunction);
    };
    Without this delegation, code that calls the standard array.sort(...) won’t use your custom implementation and the task requirement “implement Array.prototype.sort using the predefined sort2” is not satisfied.

As optional, non-blocking improvements: you could add a TypeError when compareFunction is neither undefined nor a function, and you might later consider a more efficient algorithm than bubble sort for large arrays. Once you add the Array.prototype.sort delegation, your solution will align well with the requirements; you’re very close, just missing that final connection step.


✨ 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

function applyCustomSort() {
[].__proto__.sort2 = function(compareFunction) {
// write code here
[].__proto__.sort2 = function (compareFunction) {

Choose a reason for hiding this comment

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

You define [].__proto__.sort2 here, but the task requires implementing Array.prototype.sort using that predefined sort2. Add a delegation after sort2 is defined, for example:

Array.prototype.sort = function(compareFunction) {
  return this.sort2(compareFunction);
};

This will satisfy the requirement to implement Array.prototype.sort by using sort2.


const length = this.length;

for (let i = 0; i < length; i++) {

Choose a reason for hiding this comment

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

A small suggestion: using bubble sort is acceptable for this task (and you already added an early-exit optimization). If you want to improve performance later, consider using a faster algorithm (e.g., quicksort or mergesort) for large arrays.

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

I am approving your solution because it correctly implements a custom Array.prototype.sort using [].__proto__.sort2 and then delegates Array.prototype.sort to that implementation, matching the task’s core requirements. Your sort2 uses an in-place bubble sort with an early-exit optimization, applies the correct default string comparator behavior, validates the compareFunction type, and returns this, all of which align well with the expected MDN-style behavior. There are no critical blockers: the main logic works, fulfills the feature requirements, and there are no obvious runtime errors or missing mandatory features.

If you want to improve this further, you could add tests for edge cases like sparse arrays, undefined elements, and mixed-type arrays to more closely mirror the full MDN Array.prototype.sort behavior. Another optional enhancement would be to leave a short comment explaining that Array.prototype.sort intentionally delegates to sort2, for future maintainers. For real-world performance, consider a more efficient algorithm than bubble sort, but for this exercise your current approach is fully acceptable. Nicely done overall—your implementation is clear, correct for the assignment, and thoughtfully structured.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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