Skip to content

Commit

Permalink
feat(calc emoji string length): add calc emoji length
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellipse120 committed Sep 22, 2023
1 parent 8f13b1c commit 8ebb763
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions note.md
Original file line number Diff line number Diff line change
Expand Up @@ -4491,3 +4491,23 @@ generateOTP()
```
---
## 160. Calculate string with emoji's length
```js
const emojis = [`πŸ”₯`, `πŸ€Όβ€β™‚οΈ`, 'πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦']

emojis.forEach((s) => {
console.log(`${s} `, s.length) // 2 5 11
})

const stringLength = (str) => {
return Array.from(new Intl.Segmenter().segment(str)).length
}

emojis.forEach((s) => {
console.log(`${s} `, stringLength(s)) // 1 1 1
})
```
---

0 comments on commit 8ebb763

Please sign in to comment.