Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
11
Task/Reverse-a-string/JavaScript/reverse-a-string-2.js
Normal file
11
Task/Reverse-a-string/JavaScript/reverse-a-string-2.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a = "\u{1F466}\u{1F3FB}\u{1f44b}"; // '👦🏻👋'
|
||||
|
||||
// wrong behavior - ASCII sequences
|
||||
a.split('').reverse().join(''); // '\udc4b🁦\ud83d'
|
||||
|
||||
// wrong behavior - Unicode code points
|
||||
[...a].reverse().join(''); // '👋🏻👦'
|
||||
a.split(/(?:)/u).reverse().join(''); // '👋🏻👦'
|
||||
|
||||
// correct behavior - Unicode graphemes
|
||||
[...new Intl.Segmenter().segment(a)].map(x => x.segment).reverse().join('') // 👋👦🏻
|
||||
Loading…
Add table
Add a link
Reference in a new issue