Using :str.split('') does not work at all well with Unicode characters. [...str] is much better, but still not perfect.
:str.split('')
[...str]
import ReverseString from "./reverse-string" // … it('emoji grapheme clusters', () => { // multi-codepoint grapheme clusters const emojis = [ '\uD83C\uDF37', '\uD83C\uDF81', '\uD83D\uDCA9', '\uD83D\uDE1C', '\uD83D\uDC4D', '\uD83C\uDFF3\uFE0F\u200d\uD83C\uDF08' ]; const input = emojis.join(''); const expected = emojis.reverse().join(''); expect(ReverseString.reverse(input)).toEqual(expected); })
grapheme-splitter
The Intl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.
The String object is used to represent and manipulate a sequence of characters.
Yup, I was too tired to go into these last night 👍
Awesome API! Shame it's missing in FF
It only became part of the Internationalization API Specification (ECMA 402) with ES2022.
bugzilla.mozilla.org/show_bug.cgi?...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Using
:str.split('')does not work at all well with Unicode characters.[...str]is much better, but still not perfect.grapheme-splitter
Intl.Segmenter - JavaScript | MDN
The Intl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.
String - JavaScript | MDN
The String object is used to represent and manipulate a sequence of characters.
Yup, I was too tired to go into these last night 👍
Awesome API! Shame it's missing in FF
It only became part of the Internationalization API Specification (ECMA 402) with ES2022.
bugzilla.mozilla.org/show_bug.cgi?...