code: function rtrim(str, c, invert) {
    if (str.length === 0) {
      return '';
    }
  
    // Length of suffix matching the invert condition.
    var suffLen = 0;
  
    // Step left until we fail to match the invert condition.
    while (suffLen < str.length) {
      var currChar = str.charAt(str.length - suffLen - 1);
      if (currChar === c && !invert) {
        suffLen++;
      } else if (currChar !== c && invert) {
        suffLen++;
      } else {
        break;
      }
    }
  
    return str.substr(0, str.length - suffLen);
  }
docs: Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS. invert: Remove suffix of non-c chars instead. Default falsey.