Skip to content

Instantly share code, notes, and snippets.

@vijairamcharan
Last active October 26, 2017 14:34
Show Gist options
  • Save vijairamcharan/60366b038633f88f9ffb53ab3bd3b8aa to your computer and use it in GitHub Desktop.
Save vijairamcharan/60366b038633f88f9ffb53ab3bd3b8aa to your computer and use it in GitHub Desktop.
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