Work on refactoring some javascript.
Before:
const MyFunction = function (key) {
if (key) {
switch (key) {
case "ABC":
return "Info 1";
case "DEF":
return "Info 2";
case "GHI":
return "Info 3";
case "JKL":
return "Info 4";
case "MNO":
return "Info 5";
}
}
return "";
};
After
const MyFunction = function (key) {
const data = {
"ABC": "Info 1",
"DEF": "Info 2",
"GHI": "Info 3",
"JKL": "Info 4",
"MNO": "Info 5"
};
return data[key];
};
Sweet~!
No comments:
Post a Comment