417
418
function reverse(str: string): string {
419
>
// create a Uint16Array and then use a TextDecoder to create a string
richEditBrackets.ts
420
>
const arr = new Uint16Array(str.length);
421
>
let offset = 0;
422
>
for (let i = str.length - 1; i >= 0; i--) {
423
>
arr[offset++] = str.charCodeAt(i);
424
>
}
425
>
return stringBuilder.getPlatformTextDecoder().decode(arr);
426
>
}
427
428
let lastInput: string | null = null;
429
let lastOutput: string | null = null;
430
return function toReversedString(str: string): string {
432
>
lastInput = str;
433
>
lastOutput = reverse(lastInput);
434
>
}
435
>
return lastOutput!;
436
>
};
437
})();
438