August 2024
Intermediate to advanced
516 pages
11h 47m
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 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.
Below is some code that accomplishes this. What is its Big O?
| | function averageCelsius(fahrenheitReadings) { |
| |
Read now
Unlock full access