Home > Article > Web Front-end > JavaScript Fun Question: Fragrance Vaporizer
This topic is to test an evaporator filled with fragrance to see its service life.
We know the capacity content of the evaporator (calculated in ml), and the fragrance contained in it will evaporate a certain percentage every day (evap_per_day).
This evaporator requires at least threshold (percentage) of fragrance, otherwise it can no longer be used.
All numbers are positive.
How many days will it take for the evaporator to fail?
The function prototype is as follows:
function evaporator(content, evap_per_day, threshold)
The parameters are capacity, volatilization percentage, and minimum percentage.
For this question, it actually doesn’t matter whether the capacity is used or not. It can also be solved using only percentages, but I think capacity is better to understand.
The following is the solution to the capacity. It determines how much capacity remains after evaporation every day until the current capacity is less than the minimum limit capacity and returns the number of days.
function evaporator(content, evap_per_day, threshold){ var day = 0; threshold = content * threshold / 100; while(content >= threshold){ content *= (1 - evap_per_day / 100); day++; } return day; }
The above is the content of JavaScript fun question: Fragrance evaporator. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!