How does js determine the same element in two strings and output the same element?

S1 and S2 are string types. Writing a function returns the same number of characters at the beginning of S1 and S2

Apr.07,2021

function fiterStr(str1,str2){
    var l = str1.length > str2.length ? str2.length : str1.length, //
        i = 0
    while(i < l){
        if(str1[i] !== str2[i])break
        iPP
    }
    return str1.substr(0,i)
}
fiterStr('ssd','sss'); //'ss'

double for loops


Please describe the problem clearly
what is the same number of characters at the beginning?

Menu