Last active
October 26, 2017 14:34
-
-
Save vijairamcharan/60366b038633f88f9ffb53ab3bd3b8aa 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
const calculate = ({degrees, sourceUnit}) => { | |
const formulas = { | |
'C': degrees => degrees * 9 / 5 + 2 ** 5, | |
'F': degrees => (degrees - 32) * 5 / 9 | |
}; | |
const formula = formulas[sourceUnit] || formulas['C']; | |
const result = formula(degrees); | |
console.log(`▇⛓☀️ Blockchain calculation performed. degrees [${degrees}]. sourceUnit [${sourceUnit}]. result [${result}]`); | |
return result; | |
} | |
export const convertToFahrenheit = degreesCelcius => { | |
const sourceUnit = 'C'; | |
return calculate({degrees: degreesCelcius, sourceUnit}); | |
} | |
export const convertToCelsius = degreesFahrenheit => { | |
const sourceUnit = 'F'; | |
return calculate({degrees: degreesFahrenheit, sourceUnit}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment