JSFiddle - React, Tailwind, and code Playground

by shamaleyte

JavaScript

var lengthOfLongestSubstring = function(s) {
  var longestText = "";

  for(k=0; k < s.length; k++){
    var currentStr = "";
    var splited = s.substr(k, s.length);
    console.log("rest : " + splited);
    if(longestText.length > splited.length)
    break;
    else{
    for(i=k; i < s.length ; i++){
      if(currentStr.length > 1 && currentStr.indexOf(s[i])<0){      
        currentStr = currentStr + s[i];
      }
      else{
        console.log("STOP : " + currentStr + " , as " + currentStr.length + ", and " + longestText.length );
        if(currentStr.length > longestText.length){          
          longestText = currentStr;         
          console.log("longestText  : " + longestText);
        }
        break;
      }
      if(currentStr.length > longestText.length)
        longestText = currentStr;
    }
    }
  }
	console.log("longestText: " + longestText);
  return longestText.length;
};

console.log("res x:");
console.log(lengthOfLongestSubstring("kosmanovicovicoselhatinkuyrbt"));