I problem is in javaScript I want a list of cities with each city associated with a range of temperature such as Manchester 10-20, London 21-30. When a user inputs a temperature it tells the associated city (user inputted 22 London will be outputted).
My initial idea was to have a String array of cities then map users input to the index of the city. So user inputs 22 it maps it to index 2 (London).
But inputting a city later on will be really hard.
My second idea was just a ton if else statements starting with the lowest band.
These are my two ideas, I was wondering what it the best way to solve this problem.
Make a 3 dimension
array [City][low-temp][high-temp]
If a user gives input run all cities and compare if the input is
low-temp < input < high-temp
and return list of cities which meet the condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With