Edit: more complete solution, and fixed off-by-one error:
var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !===== prev); prev = randNumber; } Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalEdit: more complete solution, and fixed off-by-one error:
var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !===== prev); prev = randNumber; } Edit: more complete solution, and fixed off-by-one error:
var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !== prev); prev = randNumber; } Edit: more complete solution, and fixed off-by-one error:
var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber === prev); prev = randNumber; }