JSFiddle - React, Tailwind, and code Playground

by LyndseyB

JavaScript

var line = "adcdefg", 
    cur = '', 
    counter = 0;

for(var i = 0, a = line.length; i<a; i++) {
    var item = line[i]; 
    
    if(cur.indexOf(item) !== -1) {
        break;
    }    
    cur+= item; 
    counter++;   
}

console.log(counter);