Last active
May 16, 2023 19:05
-
-
Save jgphilpott/8260eeb1816dd4d786268f0ac5085d55 to your computer and use it in GitHub Desktop.
A collection of functions for converting between different units of temperature.
This file contains hidden or 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
### Temperature Conversions ### | |
convertTemperature = | |
celsius: {} | |
fahrenheit: {} | |
kelvin: {} | |
### Celsius Conversions ### | |
convertTemperature.celsius.celsius = c$c = (c) -> c # Celsius to Celsius | |
convertTemperature.celsius.fahrenheit = c$f = (c) -> c * (9 / 5) + 32 # Celsius to Fahrenheit | |
convertTemperature.celsius.kelvin = c$k = (c) -> c + 273.15 # Celsius to Kelvin | |
### Fahrenheit Conversions ### | |
convertTemperature.fahrenheit.celsius = f$c = (f) -> (f - 32) * (5 / 9) # Fahrenheit to Celsius | |
convertTemperature.fahrenheit.fahrenheit = f$f = (f) -> f # Fahrenheit to Fahrenheit | |
convertTemperature.fahrenheit.kelvin = f$k = (f) -> (f - 32) * (5 / 9) + 273.15 # Fahrenheit to Kelvin | |
### Kelvin Conversions ### | |
convertTemperature.kelvin.celsius = k$c = (k) -> k - 273.15 # Kelvin to Celsius | |
convertTemperature.kelvin.fahrenheit = k$f = (k) -> (k - 273.15) * (9 / 5) + 32 # Kelvin to Fahrenheit | |
convertTemperature.kelvin.kelvin = k$k = (k) -> k # Kelvin to Kelvin |
This file contains hidden or 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
/* Temperature Conversions */ | |
var c$c, c$f, c$k, convertTemperature, f$c, f$f, f$k, k$c, k$f, k$k; | |
convertTemperature = { | |
celsius: {}, | |
fahrenheit: {}, | |
kelvin: {} | |
}; | |
/* Celsius Conversions */ | |
convertTemperature.celsius.celsius = c$c = function(c) { | |
return c; // Celsius to Celsius | |
}; | |
convertTemperature.celsius.fahrenheit = c$f = function(c) { | |
return c * (9 / 5) + 32; // Celsius to Fahrenheit | |
}; | |
convertTemperature.celsius.kelvin = c$k = function(c) { | |
return c + 273.15; // Celsius to Kelvin | |
}; | |
/* Fahrenheit Conversions */ | |
convertTemperature.fahrenheit.celsius = f$c = function(f) { | |
return (f - 32) * (5 / 9); // Fahrenheit to Celsius | |
}; | |
convertTemperature.fahrenheit.fahrenheit = f$f = function(f) { | |
return f; // Fahrenheit to Fahrenheit | |
}; | |
convertTemperature.fahrenheit.kelvin = f$k = function(f) { | |
return (f - 32) * (5 / 9) + 273.15; // Fahrenheit to Kelvin | |
}; | |
/* Kelvin Conversions */ | |
convertTemperature.kelvin.celsius = k$c = function(k) { | |
return k - 273.15; // Kelvin to Celsius | |
}; | |
convertTemperature.kelvin.fahrenheit = k$f = function(k) { | |
return (k - 273.15) * (9 / 5) + 32; // Kelvin to Fahrenheit | |
}; | |
convertTemperature.kelvin.kelvin = k$k = function(k) { | |
return k; // Kelvin to Kelvin | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment