I'm checking whether a word is real or not by referencing an object that looks like this:
dictionary.js
var dictionary = {
"apple" : "apple",
"banana" : "banana",
"orange" : "orange"
}
In JavaScript, because of the keys, the checking is "instant" (I forget the name of the lower-level phenomena in data storage that makes this possible) (hash table), rather than looping through the whole object to find a match:
if (dictionary["apple"]){
//word is valid
}
But what bothers me about this is that each word is listed twice, when the value of each property's key is never used. The property's key (name) is the only thing checked, with the value being redundant. This bothers me because for one thing, redundancy in programming looks very bad, and also this dictionary array holds over 100,000 words, and this object which must be loaded to the page (page load time) and then stored in memory (RAM being utilized) as an object is twice the necessary size.
My first idea is to just remove the values:
var dictionary = {
"apple" : "",
"banana" : "",
"orange" : ""
}
But that looks weird. So, my question is:
Is there a better way to do this?