Skip to content

function reverse currently mishandles strings that include surrogate code units #295

@Andrew-Cottrell

Description

@Andrew-Cottrell

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( '' );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions