10 XP challenge
Count Thermostat Changes
easy
Build it yourself · 6 min
1 Learn2 Predict3 Solve
TaskYour mission
A heater begins off. Turn it on when a reading is below low, and turn it off when a reading is above high. At or between the bounds, keep its state. Return the number of switches. low < high. All lists have at most 20 items; text is ASCII and at most 30 characters. Numeric inputs and list items are between -100 and 100 unless a narrower range is stated.
Examples
| Input | Return |
|---|---|
numbers = [], low = 2, high = 5 | 0 |
numbers = [1,1,3,6], low = 2, high = 5isOn: false → true → false. answer: 0 → 1 → 2. The result is 2. | 2 |
Your code
Write your answer inside Solution, then use return to send it back.
Ln 1, Col 1
JavaScript
Try examples runs the public examples. Check my code checks your full answer and saves your completion.