String.prototype.toWellFormedintermediate'hello'.toWellFormed() // β 'hello'
'π'.toWellFormed() // β 'π'
'οΏ½'.toWellFormed() // β 'οΏ½'Use toWellFormed() to replace lone surrogate code units with the Unicode replacement character U+FFFD (ES2024).
str.toWellFormed() returns a new string where lone surrogates are replaced with the Unicode replacement character U+FFFD ('\uFFFD'). A well-formed string is returned unchanged.
Challenge: Implement ensureWellFormed(str) that calls toWellFormed().
ensureWellFormed('hello') // β 'hello'