Tori is a climate journalist and she wants to write an article about the weather in different cities. She has data about the weather in different cities and she wants to rank them based on their temperature, but some of the temperatures are in Fahrenheit and some are in Celsius. She needs your help to convert the temperatures to the same unit and rank them.
Define the fahrenheit_to_celsius function that takes a temperature in Fahrenheit as an argument and returns the temperature in Celsius.
To convert Fahrenheit to Celsius subtract 32 from the Fahrenheit value, and then divide the result by 1.8.
fahrenheit_to_celsius(72.5)
// -> 22.5Define the compare_temperature function that takes two temperatures and returns an Order value indicating whether the first temperature is less than, equal to, or greater than the second temperature.
compare_temperature(Celsius(30.5), Fahrenheit(82.1))
// -> GtDefine the sort_cities_by_temperature function that takes a list of cities and returns them from coldest to warmest.
sort_cities_by_temperature([
City(name: "London", temperature: Celsius(30.5)),
City(name: "Paris", temperature: Fahrenheit(82.1))
])
// -> [
// City(name: "Paris", temperature: Fahrenheit(82.1)),
// City(name: "London", temperature: Celsius(30.5)))
// ]Tori is a climate journalist and she wants to write an article about the weather in different cities. She has data about the weather in different cities and she wants to rank them based on their temperature, but some of the temperatures are in Fahrenheit and some are in Celsius. She needs your help to convert the temperatures to the same unit and rank them.
Define the fahrenheit_to_celsius function that takes a temperature in Fahrenheit as an argument and returns the temperature in Celsius.
To convert Fahrenheit to Celsius subtract 32 from the Fahrenheit value, and then divide the result by 1.8.
fahrenheit_to_celsius(72.5)
// -> 22.5Define the compare_temperature function that takes two temperatures and returns an Order value indicating whether the first temperature is less than, equal to, or greater than the second temperature.
compare_temperature(Celsius(30.5), Fahrenheit(82.1))
// -> GtDefine the sort_cities_by_temperature function that takes a list of cities and returns them from coldest to warmest.
sort_cities_by_temperature([
City(name: "London", temperature: Celsius(30.5)),
City(name: "Paris", temperature: Fahrenheit(82.1))
])
// -> [
// City(name: "Paris", temperature: Fahrenheit(82.1)),
// City(name: "London", temperature: Celsius(30.5)))
// ]