function fancyCount(str){
const joiner = "\u{200D}";
const split = str.split(joiner);
let count = 0;
for(const s of split){
//removing the variation selectors
const num = Array.from(s.split(/[\ufe00-\ufe0f]/).join("")).length;
count += num;
}
//assuming the joiners are used appropriately
return count / split.length;
}
console.log(fancyCount("F
To sumarize my comments:
That's just the lenght of that string.
Some chars involve other chars as well, even if it looks like a single character.
"̉mủt̉ả̉̉̉t̉ẻd̉W̉ỏ̉r̉̉d̉̉".length == 24
From this (great) blog post, they have a function that will return correct length:
Javascript (and Java) strings use UTF-16 encoding.
Unicode codepoint U+0046 (
F
) is encoded in UTF-16 using 1 codeunit:0x0046
Unicode codepoint U+1D12A (