Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created July 8, 2017 23:24
Show Gist options
  • Save Woodsphreaker/6c9f03051b316839680280c15cc04aa2 to your computer and use it in GitHub Desktop.
Save Woodsphreaker/6c9f03051b316839680280c15cc04aa2 to your computer and use it in GitHub Desktop.
Replace Switch
const getService = (type) => {
const pres = () => "ppt"
const doc = () => "doc"
const sheet = () => "sheet"
const text = () => "text"
const pdf = () => "pdf"
const other = () => "default"
const service = {
xls: sheet,
xlsx: sheet,
doc: doc,
docx: doc,
ppt: pres,
pptx: pres,
txt: text,
pdf: pdf,
other: other
}
return (service[type] || service["other"])()
}
console.log(getService("docx"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment