function getLetterData(letter) {
letterData[letter] = {
count: undefined ? 1 : letterData[letter]['count']++,
overlap: overlapValue(letter)
};
}
function overlapValue(letter) {
console.log(letter);
return overlapLetters.includes(letter);
}
Hey all, I am trying to run a simple app to track the appearance of letters in a user-given string. I'm trying to organize data in an object that records the count for characters in the current string, and whether or not any characters have appeared in previous strings. As you can see above, to get the count I am checking if a value exists. If not, a 1 should be returned. If a value exists on count, it is incremented. My problem is I am unable to get a value out of letterData[letter]['count']; this results in a TypeError: letterData[letter] is undefined; can't access its "count" property.
I am led to believe that my letter variable is not being used on this line, and instead the program is trying to read letterData[letter]['count'] as if 'letter' is a literal string. Is there something else that must be done to access a key with a variable within a nested object? I don't have any issue getting overlapValue() to properly evaluate using the variable.
undefined ? 1 : letterData[letter]['count']++? It will never evaluate to 1. Also, where areletterDataandoverlapLettersdefined? Posting a full sample would be better.