I am checking three elements on the DOM to see if they are empty or not so that I can run only the Ajax calls that I should run and save on overall bandwidth. The code works but it "smells bad". Here is my source.
const processValues = (area, city, text) => { if (area.val() && city.val() && text.val()) { return 'all'; } else if (area.val() && city.val() && !text.val()) { return 'areaCity'; } else if (area.val() && !city.val() && text.val()) { return 'areaText'; } else if (area.val() && !city.val() && !text.val()) { return 'city'; } else if (!area.val() && city.val() && text.val()) { return 'cityText'; } else if (!area.val() && !city.val() && text.val()) { return 'text'; } else if (!area.val() && city.val() && !text.val()) { return 'city'; } else { return 'none'; } }; I will be repeating this check in a few methods and I will be using a switch statement in those methods with the returned string values. If there is a better way to do this, I would appreciate it.