function getLongestSubStr(s){
  const { length } = s;
  let str = ' ';
  let longest = 0;
  for (let index = 0; index < length; index+=1) {
    const cur = s.charAt(index);
    const indexOfChar = str.indexOf(cur);
    if(indexOfChar === -1){
      str += cur;
      longest = longest < str.length ? str.length : longest;
    } else{ str = str.substr(indexOfChar + 1) + cur; }}return [str, longest];
}
Copy the code