Skip to content

Created sort method#2447

Open
AndreyKagaml wants to merge 3 commits into
mate-academy:masterfrom
AndreyKagaml:develop
Open

Created sort method#2447
AndreyKagaml wants to merge 3 commits into
mate-academy:masterfrom
AndreyKagaml:develop

Conversation

@AndreyKagaml
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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

Good job implementing the custom sort2 method. I am requesting changes because the default comparison logic has a critical bug that causes a crash. Specifically, calling .toString() on null or undefined elements throws a TypeError. Your implementation should handle these values gracefully, similar to the native sort() method which moves them to the end of the array. Also, please update the comparison logic to return 0 for equal elements, as required by the standard compareFunction specification. After you fix these two issues, your solution will be ready for approval.


✨ 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 thread src/arrayMethodSort.js Outdated
Comment thread src/arrayMethodSort.js Outdated
Copy link
Copy Markdown

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

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link
Copy Markdown

@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 work on fixing the TypeError and correctly handling equal elements! Your solution is very close. However, changes are needed because the default comparison logic doesn't move null or undefined values to the end of the array as required. Your current implementation treats them as equal to other elements, so their position doesn't change during the sort. To fix this, please update your default comparison function to handle these cases specifically. If one value is null/undefined and the other is not, the null/undefined value should be considered 'greater' to ensure it's sorted to the end.


✨ 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 thread src/arrayMethodSort.js
Copy link
Copy Markdown

@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 this submission to help you move forward, but please take a moment to review the feedback as there's a key part of the logic that needs correction. You've done a great job refactoring the default comparison function, and you're very close to the correct solution!

The main issue is that the default comparison logic in src/arrayMethodSort.js doesn't correctly handle all cases for null and undefined values, causing them to be sorted to the beginning of the array instead of the end. For instance, cmp(5, undefined) incorrectly returns 1, treating 5 as greater than undefined.

To fix this, you'll need to adjust the logic to differentiate between when the first value is nullish versus when the second value is. A good approach is to check s1 for null/undefined, then check s2, and return 1, -1, or 0 accordingly before attempting the string comparison. Keep up the excellent effort!


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

Footnotes

  1. Rate AI review example

Comment thread src/arrayMethodSort.js
Comment on lines +11 to +13
if (s1 === null || s2 === undefined) {
return 1;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This condition doesn't correctly handle all cases for null and undefined values. For instance, cmp(5, undefined) will return 1, which means 5 is considered greater than undefined. This will cause undefined values to move to the beginning of the array, but they should be moved to the end. The logic needs to differentiate between s1 being nullish and s2 being nullish.

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