Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/String-length/Lambdatalk/string-length.lambdatalk
Normal file
33
Task/String-length/Lambdatalk/string-length.lambdatalk
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{script
|
||||
LAMBDATALK.DICT["W.unicodeLength"] = function() {
|
||||
function countCodePoints(str) {
|
||||
var point,
|
||||
index,
|
||||
width = 0,
|
||||
len = 0;
|
||||
for (index = 0; index < str.length;) {
|
||||
point = str.codePointAt(index);
|
||||
width = 0;
|
||||
while (point) {
|
||||
width += 1;
|
||||
point = point >> 8;
|
||||
}
|
||||
index += Math.round(width/2);
|
||||
len += 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
var args = arguments[0].trim();
|
||||
return countCodePoints(args)
|
||||
};
|
||||
}
|
||||
|
||||
Testing:
|
||||
|
||||
{W.length Hello, World!} -> 13
|
||||
|
||||
{W.length José} -> 4
|
||||
{W.unicodeLength José} -> 4
|
||||
|
||||
{W.length 𝔘𝔫𝔦𝔠𝔬𝔡𝔢} -> 14
|
||||
{W.unicodeLength 𝔘𝔫𝔦𝔠𝔬𝔡𝔢} -> 7
|
||||
Loading…
Add table
Add a link
Reference in a new issue