2019-01-04 09:05:44 +01:00
|
|
|
const Ranking = {
|
2019-08-18 10:17:09 +02:00
|
|
|
getStringRank(s1, s2) {
|
2019-08-18 16:14:47 +02:00
|
|
|
if (!s1 || !s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
let ix = indexOf(s1, s2);
|
2019-01-04 09:05:44 +01:00
|
|
|
if (ix === 0 && s1.length === s2.length) {
|
|
|
|
return 10;
|
|
|
|
} else if (ix === 0) {
|
|
|
|
return 5;
|
|
|
|
} else if (ix > 0) {
|
|
|
|
return 3;
|
|
|
|
}
|
2019-08-18 16:14:47 +02:00
|
|
|
ix = indexOf(s2, s1);
|
2019-01-04 09:05:44 +01:00
|
|
|
if (ix === 0) {
|
|
|
|
return 5;
|
|
|
|
} else if (ix > 0) {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-18 16:14:47 +02:00
|
|
|
function indexOf(target, search) {
|
|
|
|
if (target.isProtected) {
|
|
|
|
return target.indexOfLower(search);
|
|
|
|
}
|
|
|
|
if (search.isProtected) {
|
|
|
|
return search.indexOfSelfInLower(target);
|
|
|
|
}
|
|
|
|
return target.indexOf(search);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.Ranking = Ranking;
|
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { Ranking };
|