S
S
sergeu902018-01-18 21:33:24
JavaScript
sergeu90, 2018-01-18 21:33:24

Store list of cities in database or use services?

There was a question that haunts me. How best to implement such a case. When filling out the form, the user can specify the city from the list. Where is the best way to get cities from your database or from the api of other developers? If you use the services, then we exclude such costs? Advise who faced such a problem and how did you solve it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rustam Azizov, 2019-11-05
@incentive

paw(2, 5) = 2 * paw(2, 4)
2 * paw(2, 4)                   --> paw(2, 4) = 2 * paw(2, 3)
2 * (2 * paw(2, 3))             --> paw(2, 3) = 2 * paw(2, 2)
2 * (2 * (2 * paw(2, 2)))       --> paw(2, 2) = 2 * paw(2, 1)
2 * (2 * (2 * (2 * paw(2, 1)))) --> paw(2 ,1) = 2
2 * (2 * (2 * (2 * 2)))

On line 3, not the finished result, but simply the value of res and it is simply substituted instead of the recursive function call on the fifth.

M
McBernar, 2019-11-05
@McBernar

Your function calls itself.
The intermediate result is written to res and passed to this new call.
All calculations start only when the recursion reaches the end and returns res.
Here is a picture for your example. Pay attention to the green rectangles.
recursion.png

B
basrach, 2018-01-20
@basrach

In any case, you need to keep it to yourself. It's not even up for debate. So that your service does not stop working, figuratively speaking, due to the fact that somewhere on the other side of the world a cleaner touched a wire with a mop. But as you correctly noted, another problem arises - the relevance of the data. And it's pretty easy to solve. Take data from a third-party api periodically and update the data in your database. How often to do this, and how, to completely replace local data / pull only updates, etc.? - It depends on the amount of data, the nature of this data, etc. In the case of a list of cities, it is probably possible to do an automatic update once a month or even once a quarter, or even once a year. Not so often appear/disappear/rename cities. And if necessary, you can start the update manually.
If you don't follow this advice and decide to start without a local copy. Then soon you will still have to redo it. Because in the real world, networks break, servers crash, firewalls cut traffic, and services suddenly stop responding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question