Skip to content

Instantly share code, notes, and snippets.

@gaogao-9
Last active November 8, 2017 01:41
Show Gist options
  • Save gaogao-9/dbb53406bb4206bebaec231e92642088 to your computer and use it in GitHub Desktop.
Save gaogao-9/dbb53406bb4206bebaec231e92642088 to your computer and use it in GitHub Desktop.
var text = "ハムマンのマンマンをハムハムしたいおっお(^ω^)❤";
console.log(twitterCount(text)); // 25
function twitterCount(text) {
return [...text]
.map((s)=> s.codePointAt())
.map((c)=> {
switch(true){
case (c <= 0x10ff):
case (c >= 0x2000 && c <= 0x200d):
case (c >= 0x2010 && c <= 0x201f):
case (c >= 0x2032 && c <= 0x2037):
return 0.5;
default:
return 1;
}
})
.reduce((a,b)=> a+b, 0) + 0.5 | 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment