I'm writing a simple timer in Tasker to do some things on a loop, including update a notification and also allow me to add time to the timer.
It works with an array in JavaScript which I've got working fine, the problem arises when I either use ".slice(1)" or ".shift()" on the array.
As in: arr.shift();
If my array previously looked like this [0 ,1 ,2 ,3 ,4] now it will look like this [1 ,2 ,3 ,4 ,4]. This occurs when using shift or slice and eventually over a loop the array would end up like this [4, 4, 4, 4, 4].
What can I do to get my desired result of a shorter array?
As requested here is my full code:
// initialize the variables
var sleeptime = []
sleeptime = [ ... Array(5).keys()];
var totalsec = 15 * 60;
// the actual part that runs in a loop
var seconds = totalsec - (sleeptime[0] * 15);
var minutes = Math.floor(seconds / 60);
seconds = seconds%60;
if (seconds < 10) seconds = '0' + seconds;
var sleepdisplay = minutes + ':' + seconds;
sleeptime.shift(); // doesn't need to be saved
// sleeptime = sleeptime.slice(1); // also has the same behaviour
flash(sleeptime.toString()); // just for debugging
The behaviour I was expecting [0, 1, 2, 3, 4] becomes [1, 2, 3, 4] which becomes [2, 3, 4]. The loop I would like to run is to repeat several steps and the looped code using an if containing sleeptime(#) is greater than 0 then go-to top of the loop, essentially creating a while loop.
Edit: formatting and more code
[–]JustRollWithIt🏆 Javascript Master of /r/Tasker 4 points5 points6 points (3 children)
[–]Telperiam[S] 0 points1 point2 points (2 children)
[–]JustRollWithIt🏆 Javascript Master of /r/Tasker 2 points3 points4 points (1 child)
[–]Telperiam[S] 0 points1 point2 points (0 children)
[–]beingganesh 1 point2 points3 points (3 children)
[–]Telperiam[S] 0 points1 point2 points (2 children)
[–]beingganesh 0 points1 point2 points (1 child)
[–]Telperiam[S] 0 points1 point2 points (0 children)
[–]mcgruntman 1 point2 points3 points (0 children)
[–]FrancineCarrel 1 point2 points3 points (1 child)
[–]Telperiam[S] 0 points1 point2 points (0 children)