function rtrim(str, c, invert) {
    const l = str.length;
    if (l === 0) {
        return '';
    }

    // Length of suffix matching the invert condition.
    let suffLen = 0;

    // Step left until we fail to match the invert condition.
    while (suffLen < l) {
        const currChar = str.charAt(l - suffLen - 1);
        if (currChar === c && !invert) {
            suffLen++;
        } else if (currChar !== c && invert) {
            suffLen++;
        } else {
            break;
        }
    }

    return str.substr(0, l - suffLen);
}
// invert: Remove suffix of non-c chars instead. Default falsey.
Remove suffix of non-c chars instead. Default falsey.
Remove suffix of non - c chars instead . Default falsey .
function rtrim(str, c, invert) {
    const l = str.length;
    if (l === 0) {
        return '';
    }
    let suffLen = 0;
    while (suffLen < l) {
        const currChar = str.charAt(l - suffLen - 1);
        if (currChar === c && !invert) {
            suffLen++;
        } else if (currChar !== c && invert) {
            suffLen++;
        } else {
            break;
        }
    }
    return str.substr(0, l - suffLen);
}
function rtrim ( str , c , invert ) { const l = str . length ; if ( l === 0 ) { return '' ; } let suffLen = 0 ; while ( suffLen < l ) { const currChar = str . charAt ( l - suffLen - 1 ) ; if ( currChar === c && ! invert ) { suffLen ++ ; } else if ( currChar !== c && invert ) { suffLen ++ ; } else { break ; } } return str . substr ( 0 , l - suffLen ) ; }
invert: Remove suffix of non-c chars instead.
invert : Remove suffix of non - c chars instead .
// Length of suffix matching the invert condition. // Step left until we fail to match the invert condition.