I have an array [1,1,1,0]
(any size of), the minimum length of array and number 1 is 3. I want to keep moving the value of 1s 1 element up so it could move to [0,1,1,1]
, then back to [1,1,1,0]
.
My loop sort of work in recursive mode, but I'm not sure how to reset the values, so after 4 loops, my entire array is filled with 0's.
More lengthily array would traverse as so:
Example:
[1,1,1,0,0,0]-> [0,1,1,1,0,0]-> [0,0,1,1,1,0]-> [0,0,0,1,1,1]->
[1,1,0,0,0,1]-> [1,1,1,0,0,0]-> [0,1,1,1,0,0]-> [0,0,1,1,1,0]->
And so on for ever...
Code:
function flip(images, active) {
var new_active = active;
setTimeout(function() {
active.reverse();
active[active.length] = 0;
active.reverse();
active.pop();
for(var i = 0; i < active.length; i++) {
alert(active[i]);
}
flip(images, active);
}, 5000);
}