Uncertain of the reason for this issue. In this part of my code, these arrays might contain only a single element.
actualAnswer = actualAnswer.split(" ");
playerAnswer = playerAnswer.split(" ");
Next, I put them through this function.
function checkForPlural(playerAnswer, actualAnswer){
var answerObject = {playerAnswer: playerAnswer,
actualAnswer: actualAnswer};
for (var answerWord in actualAnswer){
if (actualAnswer[answerWord].slice(-1) == "S")
{
answerObject.actualAnswer[answerWord] = actualAnswer[answerWord].substring(0, actualAnswer[answerWord].length - 1);
}
}
for (var answerWord in playerAnswer){
if (playerAnswer[answerWord].slice(-1) == "S")
{
answerObject.playerAnswer[answerWord] = playerAnswer[answerWord].substring(0, playerAnswer[answerWord].length - 1);
}
}
}
Upon returning the object, if the passed arrays had just one element, Javascript interprets them as strings. Therefore, using answerObject.actualAnswer.length would provide the length of the string instead of 1.
Link to the functioning Plunker: https://plnkr.co/edit/nIqq3VdjjMa2GDWyqkxx
UPDATE: Found that the issue was actually in an earlier part of my code. Apologies!