Answer the question
In order to leave comments, you need to log in
How to quickly determine differences in a string?
There are two lines:
1. Hello
2. He_ll_o
How to determine where the words differ (character number)? What are fast algorithms?
Answer the question
In order to leave comments, you need to log in
write a loop and check the correctness and compliance of the character through indexOf ()
function compare(a,b) {
if(a==b) return 0;
var m=Math.min(a.length,b.length);
var r=m+1;
if (m>0) {
for (var i=0;i<m;i++)
if (a[i]!=b[i]) {
r=i+1;
break;
}
} else r=1;
return r;
}
var a='Hello';
var b='He_ll_o';
document.write(compare(a,b)); //3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question