Skip to content

Instantly share code, notes, and snippets.

@ozscosta
Created January 29, 2019 21:49
Show Gist options
  • Save ozscosta/258745aba90dd7e398a5241a26db64c0 to your computer and use it in GitHub Desktop.
Save ozscosta/258745aba90dd7e398a5241a26db64c0 to your computer and use it in GitHub Desktop.
const temperaturas = {
'c': {
'f': (val) => (val * 1.8 + 32),
'k': (val) => (val + 273.15),
},
'f': {
'c': (val) => (val - 32) / 1.8,
'k': (val) => (val * 1.8) - 459.67,
},
'k': {
'c': (val) => (val - 273.15),
'f': (val) => (val * 1.8) - 459.67,
}
}
const converter = (unities, val, base, to) => Number(unities[base][to](val))
converter(temperaturas, 0, 'c', 'f')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment