|
function reverse( str ) { |
FYI, function reverse
currently mishandles strings that include surrogate code units.
reverse( '𝑨𝑩𝑪' ) !== '𝑪𝑩𝑨'; // true
This limitation could be documented or the implementation could be changed. For example
function reverse( str ) {
if ( !isString( str ) ) {
throw new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );
}
return Array.from( str ).reverse().join( '' );
}