jQuery Shorten Switch Statement I have a switch statement that checks whether or not one string matched another that was stored in an array. However, there are multiple cases in which the same result is returned for multiple matches. I originally had a large amount of if/else checks, but tried to shorten that down with the switch statement. I was wondering, is there anyway to shorten down this switch statement?


function checkLoc(xstreets) {
            var address;
            if(xstreets[2] == undefined) {
                address = xstreets[0]+" & "+xstreets[1]+" Chicago IL";
            }
            else {
                switch(xstreets[2]) {
                    case "aon":
                        address = "Aon Center Chicago IL";
                        break;
                    case "trump":
                        address = "401 North Wabash Avenue, Chicago, IL";
                        break;
                    case "pritzker":
                        address = "Pritzker Park Chicago IL";
                        break;
                    case "hyde":
                    case "hydepark":
                    case "uofc":
                    case "uchicago":
                        address = "5801 South Ellis Avenue, Chicago, IL";
                        break;
                    case "reg":
                        address = "1100 E 57th St, Chicago, IL 60637";
                        break;
                    case "willis":
                    case "wttw":
                        address = "233 South Wacker Drive, Chicago, IL";
                        break;
                    case "600":
                        address = "600 West Chicago Avenue, Chicago, IL";
                        break;
                    default:
                        address = xstreets[0]+" & "+xstreets[1]+" Chicago IL";
                        break;
                }
            }
            return address;
        }
You can convert it to two array. The first will normalize multiple "aliases" of the same key into one and second will have your address values.

var aliases = {
  "hyde" : "hydepark",
  "uofc" : "hydepark",
  "uchicago" : "hydepark",
  "wttw" : "willis"
};

var addresses = {
  "hydepark" : "5801 South Ellis Avenue, Chicago, IL",
  ...
};

var alias = aliases[xstreets[2]];
if(alias == undefined) {
  alias = xstreets[2]
}
var address = addresses[alias];
if(address == undefined) {
  return xstreets[0]+" &amp; "+xstreets[1]+" Chicago IL";
}
return address;