JSFiddle - React, Tailwind, and code Playground

by David Marshall

HTML

<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
<div id="5"></div>
<div id="6"></div>
<div id="7"></div>
<div id="8"></div>
<div id="9"></div>
<div id="10"></div>
<div id="11"></div>
<div id="12"></div>
<pre id="log"></pre>

JavaScript

// counter variable
var indexCount = 0;

// log container
var log = $('#log');

// iterate over each div
$('div').each(function () {

    // start the entry
    log.append('<p>');

    // the current items index
    var current = parseInt($(this).attr('id'));

    // log the current counter
    log.append('indexCount: ' + indexCount + "\n");

    // log the current index
    log.append('current index: ' + current + "\n");

    // log the current comparison
    log.append('Index (' + indexCount + ') lower than current (' + current + '): ');

    // log the current status
    var status = false;

    // if the counter is lower than the current index...
    if (indexCount < current) {

        // set the counter to the current index value
        indexCount = current;

        // and the status to true
        status = true;
    }

    // log the current status
    log.append(status + "\n");

    // close the entry
    log.append("</p>");
});