I am new to javascript so sorry I don’t know very much. I have the following and I would like to make it simpler. Any suggestion would be appreciated.
if (entity == "house") {
primaryKey = store.getItem('accountID') + "02" + "00";
table = "Content";
}
if (entity == "street") {
primaryKey = store.getItem('accountID') + "0000";
table = "Content";
}
if (entity == "city") {
var primaryKey = store.getItem('categoryID');
table = "Reference";
}
if (entity == "location") {
primaryKey = "0001" + store.getItem('examID');
table = "Content";
}
You could do it with a table driven approach and no repeated code (DRY) like this:
Besides minimizing the code and not repeating any code, it’s also easy to add more options to the table without writing any additional code.
Or, the data table can be made a little more compact, though not quite as elegant (from a pure programming point of view because of the hard coded constants) this way:
Either way, you get the idea of using a lookup table for the entity and then a table driven approach for the different values for each entity.