I have a function that returns a string indicating the image to show for a particular file extension:
getImage = function (file) {
switch (file.extension) {
case "txt":
return "document.jpg";
case "doc":
return "document.jpg";
case "jpg":
return "image.jpg";
case "gif":
return "image.jpg";
case "png":
return "image.jpg";
case "mpg":
return "video.jpg";
// And so on for 50+ file extensions...
default:
return "file.jpg";
}
}
I need to support a large number of file extensions, so my switch statement is huge. But since a lot of the file extensions share the same image, I feel like there may be a way to group extensions together to make things more concise.
So how can I re-write this in a more concise manner? (Any answer needs to be compatible with IE8)