August 2020
Intermediate to advanced
508 pages
11h 53m
English
Here’s another example that involves mean averages. Let’s say we’re building weather-forecasting software. To determine the temperature of a city, we take temperature readings from across many thermometers across the city, and we calculate the mean average of those temperatures.
We’d also like to display the temperatures in both Fahrenheit and Celsius, but our readings are initially only provided to us in Fahrenheit.
To get the average Celsius temperature, our algorithm does two things: first, it converts all the readings from Fahrenheit to Celsius. Then, it calculates the mean average of all the Celsius numbers.
Following is some Ruby code that accomplishes this. What is its Big O?
| | def average_celsius(fahrenheit_readings) ... |
Read now
Unlock full access