You can combine cases:
getImage = function (file) {
switch (file.extension) {
case "txt":
case "doc":
return "document.jpg";
case "jpg":
case "gif":
case "png":
return "image.jpg";
case "mpg":
return "video.jpg";
// And so on for 50+ file extensions...
default:
return "file.jpg";
}
}
You can also use a map instead:
var extmap = {
"txt": "document.jpg",
"doc": "document.jpg",
"jpg": "image.jpg",
"gif": "image.jpg",
"png": "image.jpg",
"mpg": "video.jpg",
// And so on for 50+ file extensions...
};
getImage = extmap[file.extension] || "file.jpg";
...but then you can't combine cases.