Skip to content

solution#2469

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

solution#2469
blabunch wants to merge 2 commits intomate-academy:masterfrom
blabunch:develop

Conversation

@blabunch
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

I am requesting changes because the core requirement of the task is not yet fulfilled: Array.prototype.sort is not actually implemented using the predefined [].__proto__.sort2. Right now, src/arrayMethodSort.js only defines sort2 on [].__proto__, so calling [].sort() will still use the native implementation instead of your custom one. To meet the task requirements, you need to install a delegating sort implementation inside applyCustomSort(), for example attaching a function that calls this.sort2(compareFunction) on the array prototype (or [].__proto__). This is a critical blocker because it means the main behavior the tests expect—overriding Array.prototype.sort to use your bubble-sort logic—is missing.

Concretely, inside applyCustomSort(), add something like:

  • Array.prototype.sort2 = function(compareFunction) { /* your current bubble sort code */ };
  • Array.prototype.sort = function(compareFunction) { return this.sort2(compareFunction); };
    so that running applyCustomSort() configures both methods. As a minor improvement (not a blocker), you could also validate that compareFunction, if provided, is a function and throw a TypeError otherwise, which more closely matches the native sort behavior. Your bubble-sort implementation and default string-based comparison look good, so once you wire up sort to delegate to sort2, you should be in line with the task requirements.

✨ 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

}
}
}
return this;

Choose a reason for hiding this comment

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

The task requires implementing Array.prototype.sort using the predefined [].__proto__.sort2. This file only defines sort2 and never adds/overrides Array.prototype.sort. Add a delegating implementation (for example: [].__proto__.sort = function(compareFunction) { return this.sort2(compareFunction); };) inside applyCustomSort() so the exported function installs both methods.

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

Your solution is approved because it meets the core requirements of the task: you define a custom Array.prototype.sort2 and correctly delegate Array.prototype.sort to use this implementation, and the function behaves like native sort in terms of accepting an optional compareFunction and returning the original array. The validation of the compareFunction and the presence of a default comparator that falls back to string conversion both align well with MDN-style behavior and ensure correct basic functionality. There are no critical blockers such as missing features, broken runtime behavior, or violations of the explicit requirements.

A few aspects could be improved in future iterations: your bubble-sort implementation is O(n^2) and thus not ideal for very large arrays, so if performance becomes important you might consider a more efficient algorithm such as quicksort or mergesort. Also, native Array.prototype.sort has some subtle behaviors (like handling sparse arrays, this coercion via ToObject, and exact error message text) that your version only partially mirrors; these are not required for this task, but they are good areas to explore if you want closer spec parity. Overall, the code is clear, focused, and functionally correct for the assignment—nice work.


✨ 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