function randWord(wordArray, currentWord) {
let wordObject,
pickedWordObject,
safetyCounter = 0;
do {
wordObject = wordArray[randInt(wordArray.length)];
} while (typeof wordObject == 'string' && wordObject == currentWord);
let wordArrayIndex = pairIndex(currentWord, wordArray);
if (typeof wordObject == 'string' && wordArrayIndex == -1) {
return wordObject;
} else {
if (wordArrayIndex == -1) {
wordObject.display = true;
let pairIndex = randInt(2);
return wordObject.pair[pairIndex];
} else {
wordObject = wordArray[wordArrayIndex];
if (wordObject.display == false) {
return randWord(wordArray, wordObject);
}
let mateIndex = (wordObject.pair.indexOf(currentWord) + 1) % 2;
wordObject.display = false;
return wordObject.pair[mateIndex];
}
}
}