JSFiddle - React, Tailwind, and code Playground

by dbjdbj

JavaScript

/*
proof of cerctness of test cases
*/
function print (s) {
    setTimeout(function () { document.body.innerHTML += "<li>"+s+"</li>" ; }, 1 ) ;
};

    
var currentSlide = 0 , totalItems = 22;

/*
T4 from http://jsperf.com/subtract-vs-modulus/3
*/
function counter () {
return  currentSlide == totalItems ? currentSlide - totalItems + 1 : ++currentSlide ;
}
/*
T5 from http://jsperf.com/subtract-vs-modulus/3
*/
function counter2 () {
       if ( currentSlide == totalItems)
             return 1 ;
    else
        return ++currentSlide ;
}


var j = 122 ;
while ( j-- > 0 ) {
    
    print("j: " + j + ", current: " + (currentSlide = counter2()) ) ;
}