The same problems remain as in the earlier thread.
The code-unit vs codepoint distinction is indeed important, and your suggested impl is the right way to reverse by codepoint. But it still reverses strings incorrectly, such as:
function strrev(s) { return [...s].reverse().join(''); }
let accentA = "a" + String.fromCodePoint(0x301) + "e"; // 'áe'
let accentE = strrev(x); // 'éa'
let chinaFlag = "🇨🇳"; // actually 🇨 followed by 🇳
let newCaledoniaFlag = strrev(chinaFlag); // '🇳🇨', 🇳 followed by 🇨
To reverse correctly you have to recognize grapheme clusters, which are multi-codepoint. The issue is that the definition of grapheme clusters changes with the Unicode version, as we add more, so strings that reversed in a particular way at one point might change their value if we update; but if we don’t update, strings that people expect would reverse wouldn’t do so correctly. A bit of a pickle for a language like JS.
Also, grapheme clusters aren’t detectable in reverse; you have to parse them from the start of the string. The flag emojis, for example, are composed of any valid pair of flag-emoji letters; if you have more than two in a row, the first two are consumed for one flag, then the next two, etc. For example, taking 🇨 + 🇳 + 🇬 forward yields '
🇬' - China’s flag followed by an unparied 🇬. If you naively process it backwards with this strrev() you instead get '
🇨' - Guinea’s flag followed by an unpaired 🇨, But if you process it backwards and recognize country pairs so they stay in the original order, you’ll get '
🇨' - Nigeria’s flag followed by an unpaired 🇨. It is actually impossible to correctly produce a string containing an unpaired 🇬 followed by a
, which would be the ideal reversal, without inserting additional characters (a zero-width non-joining space, in this case). '🇬🇨🇳' is actually four codepoints long, and cannot be written any shorter.
So, to reverse grapheme clusters correctly you still have to do a forward scan to identify cluster boundaries (or more complicated backwards scanning to look for misgroupings), which ends up negating a lot of the perf optimization you could get, and in some cases a correct grapheme clustering is impossible to reproduce anyway without changing the data of the string.
(It’s widely recognized that the design of the flag emojis was a completely disaster for these reasons, fwiw, but they still exist.)