I must admit that I am not a mathematical expert, so I cannot solve the following problem until I am satisfied.
I have a number, let's say I = 0. I have a function that increments me on each call by 1, and then calls itself again, incrementing at another time, and another and another ... When 100 is reached, I want so that it counts back to 0, and then again, sort of like a tip loop, and I go up and down like an elevator. What is an elegant solution for this?
My decision:
var countingUp = true; var i = 0; function count() { if(i < 100 && countingUp) {i+=1} if(i > 1 && !countingUp) {i-=1} if(i===100) {countingUp=false;} if(i===1) {countingUp=true;} count() } count()
I am looking for something shorter.
source share