function longestSubStrWithSameChars(str) {
    // if empty string
    if (!str.length) return null;

    const matches = str.match(/(.)\1+/g);

    // if every character is single in str
    if (!matches) return null;

    // find the longest sub-string
    const longestSubStr = matches
        .reduce((longest, substr) => substr.length > longest.length ? substr : longest, '');

    return {
        subString: longestSubStr,
        index: str.indexOf(longestSubStr),
        length: longestSubStr.length
    };
}
/**
 * find the longest sub string with same characters in the str
 * @param {string} str
 */
find the longest sub string with same characters in the str
@param {string} str
find the longest sub string with same characters in the str @param { string } str
function longestSubStrWithSameChars(str) {
    if (!str.length) return null;
    const matches = str.match(/(.)\1+/g);
    if (!matches) return null;
    const longestSubStr = matches
        .reduce((longest, substr) => substr.length > longest.length ? substr : longest, '');
    return {
        subString: longestSubStr,
        index: str.indexOf(longestSubStr),
        length: longestSubStr.length
    };
}
function longestSubStrWithSameChars ( str ) { if ( ! str . length ) return null ; const matches = str . match ( / (.)\1+ / g ) ; if ( ! matches ) return null ; const longestSubStr = matches . reduce ( ( longest , substr ) => substr . length > longest . length ? substr : longest , '' ) ; return { subString : longestSubStr , index : str . indexOf ( longestSubStr ) , length : longestSubStr . length } ; }
find the longest sub string with same characters in the str
 @param {string} str
find the longest sub string with same characters in the str @param { string } str
// if empty string // if every character is single in str // find the longest sub-string