javascript-exercises
javascript-exercises copied to clipboard
07_reverseString: handle Unicode surrogate pairs in reverseString solution
Because
The original reverseString solution used .split(""), which does not handle complex Unicode characters correctly. This can lead to incorrect behavior when the input includes surrogate pairs (e.g., emojis or some accented characters). This PR modifies the implementation to avoid that issue and includes a comment to make learners aware of the underlying limitation.
This PR
- Updated the
reverseStringsolution to useArray.from()instead of.split("") - Added a comment explaining the issue with surrogate pairs and Unicode handling in JavaScript
Issue
N/A
Additional Information
We've already been exposed to this problem in the MDN Reference page for String, linked here. This is why I think we can consider it in this exercise.
Pull Request Requirements
- [x] I have thoroughly read and understand The Odin Project Contributing Guide
- [x] The title of this PR follows the
location of change: brief description of changeformat, e.g.01_helloWorld: Update test cases - [x] The
Becausesection summarizes the reason for this PR - [x] The
This PRsection has a bullet point list describing the changes in this PR - [x] If this PR addresses an open issue, it is linked in the
Issuesection - [x] If this PR includes any changes that affect the solution of an exercise, I've also updated the solution in the
/solutionsfolder