Skip to content

Commit

Permalink
fixed initials
Browse files Browse the repository at this point in the history
  • Loading branch information
arvitaly committed Jul 15, 2018
1 parent 0458d2a commit 61289a9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions __fixtures__/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ exports.default = [
name2: "Name2 BIGGEST",
isEqual: true,
},
{
name1: "Alexandra Bozovic",
name2: "Bolt A",
isEqual: false,
},
];
5 changes: 5 additions & 0 deletions __fixtures__/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export default [
name2: "Name2 BIGGEST",
isEqual: true,
},
{
name1: "Alexandra Bozovic",
name2: "Bolt A",
isEqual: false,
},
];
11 changes: 7 additions & 4 deletions lib/match-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@ function matchNames(name1, name2) {
const words1 = name1.split(" ").map((w) => normalizeWord_1.normalizeWord(w));
const words2 = name2.split(" ").map((w) => normalizeWord_1.normalizeWord(w));
let equalWordsCount = 0;
let shortEqualCounts = 0;
let shortEqualCount = 0;
let strictEqualCount = 0;
for (const word1 of words1) {
for (const word2 of words2) {
if (word1 === word2) {
equalWordsCount++;
strictEqualCount++;
continue;
}
if (word1.indexOf(word2) === 0 || word2.indexOf(word1) === 0) {
equalWordsCount++;
shortEqualCounts++;
shortEqualCount++;
continue;
}
}
}
const upperSymbols1 = getUpperSymbols_1.getUpperSymbols(name1);
const upperSymbols2 = getUpperSymbols_1.getUpperSymbols(name2);
if (equalWordsCount === words1.length && equalWordsCount === words2.length && shortEqualCounts < 2) {
if (equalWordsCount === words1.length && equalWordsCount === words2.length && shortEqualCount < 2) {
return true;
}
if (compareStringArrays_1.compareStringArrays(upperSymbols1, upperSymbols2) &&
Math.abs(equalWordsCount - words1.length) < 3 &&
Math.abs(equalWordsCount - words2.length) < 3 &&
shortEqualCounts < 2) {
shortEqualCount < 2 &&
strictEqualCount > 0) {
return true;
}
return false;
Expand Down
11 changes: 7 additions & 4 deletions lib/match-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ export function matchNames(name1: string, name2: string) {
const words1 = name1.split(" ").map((w) => normalizeWord(w));
const words2 = name2.split(" ").map((w) => normalizeWord(w));
let equalWordsCount = 0;
let shortEqualCounts = 0;
let shortEqualCount = 0;
let strictEqualCount = 0;
for (const word1 of words1) {
for (const word2 of words2) {
if (word1 === word2) {
equalWordsCount++;
strictEqualCount++;
continue;
}
if (word1.indexOf(word2) === 0 || word2.indexOf(word1) === 0) {
equalWordsCount++;
shortEqualCounts++;
shortEqualCount++;
continue;
}
}
}
const upperSymbols1 = getUpperSymbols(name1);
const upperSymbols2 = getUpperSymbols(name2);
if (equalWordsCount === words1.length && equalWordsCount === words2.length && shortEqualCounts < 2) {
if (equalWordsCount === words1.length && equalWordsCount === words2.length && shortEqualCount < 2) {
return true;
}
if (
compareStringArrays(upperSymbols1, upperSymbols2) &&
Math.abs(equalWordsCount - words1.length) < 3 &&
Math.abs(equalWordsCount - words2.length) < 3 &&
shortEqualCounts < 2
shortEqualCount < 2 &&
strictEqualCount > 0
) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61289a9

Please sign in to comment.