2019-06-06 11:03:00 -06:00
|
|
|
export function getHomonymnIndexes(word) {
|
|
|
|
const { currentDictionary } = window;
|
|
|
|
const { caseSensitive } = currentDictionary.settings;
|
|
|
|
const foundIndexes = [];
|
|
|
|
currentDictionary.words.forEach((existingWord, index) => {
|
|
|
|
if (existingWord.wordId !== word.wordId
|
|
|
|
&& (caseSensitive ? existingWord.name === word.name : existingWord.name.toLowerCase() === word.name.toLowerCase())) {
|
|
|
|
foundIndexes.push(index);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return foundIndexes;
|
|
|
|
}
|
2019-06-06 15:41:30 -06:00
|
|
|
|
|
|
|
export function getHomonymnNumber(word) {
|
|
|
|
const homonyms = getHomonymnIndexes(word);
|
|
|
|
if (homonyms.length > 0) {
|
|
|
|
const index = window.currentDictionary.words.findIndex(w => w.wordId === word.wordId);
|
|
|
|
let number = 1;
|
|
|
|
|
|
|
|
for (let i = 0; i < homonyms.length; i++) {
|
|
|
|
if (index < homonyms[i]) break;
|
|
|
|
number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|