Last active
January 13, 2020 15:12
-
-
Save rsmelo92/43159bc631de1148e33e489a26b9a639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *SMELL* | |
function convertTemperatures(farenheit, celcius, kelvin) { | |
const farenheitToCelcius = (5 / 9) * (farenheit - 32); | |
const farenheitToKelvin = ((farenheit - 32) / 1.8) + 273.15; | |
const celciusToFarenheit = (celcius * 1.8) + 32; | |
const celciusToKelvin = celcius + 273.15; | |
const kelvinToFarenheit = kelvin * 1.8 - 459.67; | |
const kelvinToCelcius = kelvin - 273.15; | |
return { | |
farenheitConversion: { | |
farenheitToCelcius, | |
farenheitToKelvin | |
}, | |
celciusConversion: { | |
celciusToFarenheit, | |
celciusToKelvin | |
}, | |
kelvinConversion: { | |
kelvinToFarenheit, | |
kelvinToCelcius | |
} | |
} | |
} | |
// *REFACTORED* | |
function farenheitConversion(farenheit) { | |
const toCelsius = (5 / 9) * (farenheit - 32); | |
const toKelvin = ((farenheit - 32) / 1.8) + 273.15; | |
return {toCelsius, toKelvin}; | |
} | |
function celciusConversion(celcius) { | |
const toFarenheit = (celcius * 1.8) + 32; | |
const toKelvin = celcius + 273.15; | |
return {toFarenheit, toKelvin}; | |
} | |
function kelvinConversion(kelvin) { | |
const toFarenheit = kelvin * 1.8 - 459.67; | |
const toCelcius = kelvin - 273.15; | |
return {toFarenheit, toCelcius}; | |
} | |
function convertTemperatures(farenheit, celcius, kelvin) { | |
return { | |
farenheit: farenheitConversion(farenheit), | |
celcius: celciusConversion(celcius), | |
kelvin: kelvinConversion(kelvin) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment