Let's try mozilla's fixedCharAt function

master
Caleb Fontenot 2023-04-30 19:30:16 +07:00
parent 5cf9dab550
commit 1adcc069df
1 changed files with 7 additions and 4 deletions

@ -213,15 +213,18 @@ function design4(input) {
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
var charIterateState;
function charIterate(input) {
let stringLength = (input.length - 1);
for (let i = 0; i < stringLength; ++i) {
if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) {
stringLength--;
}
}
if (charIterateState == undefined) {
console.log("undefined! setting to zero");
charIterateState = 0;
} else {
if (charIterateState < (input.length - 1)) {
if (charIterateState < stringLength) {
charIterateState++;
if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) {
//charIterateState++;
}
} else {
charIterateState = 0;
}