-
Notifications
You must be signed in to change notification settings - Fork 0
/
strCmp.js
42 lines (32 loc) · 1.09 KB
/
strCmp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function strCompare(str1, str2) {
var dif = 0,
off = 0,
maxInsertForgot = 4;
for (var c = 0; c < Math.min(str1.length, str2.length); c++) {
if (str1[c] == str2[c + off]) {
}
else if (str1[c].match(/\s$/) && str2[c].match(/\s/)) {
}
else if(str2[c + off] && str1[c] != str2[c + off]){
if(str2[c + off] && str1[c] != str2[c + off]){
dif++
}
for (var n = 1; n < maxInsertForgot; n++) {
if (str1[c] == str2[c + off + n]) {
off++
break
}
}
for(var n = 1; n < maxInsertForgot; n++){
if (str1[c + n] == str2[c + off]) {
off--
break;
}
}
}
}
return {
dif: dif,
off: off
}
}