Jquery iterating independently inside $each help :(

https://codepen.io/rurounisena/pen/NeGjyq

HTML

<div class='myDiv'>
    <table summary='Bulk Tracking'>
      <span title='Bulk Tracking'>Bulk Tracking</span>

      <tr>
        <td>IL</td>
        <td>NR</td>
        <td><span class='ms-nowrap'>12/1/2018</span></td>
        <td>65</td>
        <td class='lastCell'>Waiting For</td>
      </tr>
      <tr>
        <td>TX</td>
        <td>FT</td>
        <td><span class='ms-nowrap'>12/9/2018</span></td>
        <td>22</td>
        <td class='lastCell'>Waiting For</td>
      </tr>
      <tr>
        <td>WY</td>
        <td>ND</td>
        <td><span class='ms-nowrap'>12/25/2018</span></td>
        <td>721</td>
        <td class='lastCell'>Waiting For</td>
      </tr>
      <tr>
        <td>MT</td>
        <td>NR</td>
        <td><span class='ms-nowrap'>12/7/2018</span></td>
        <td>33</td>
        <td class='lastCell'>Waiting For</td>
      </tr>
      <tr>
        <td>AK</td>
        <td>LR</td>
        <td><span class='ms-nowrap'>12/7/2018</span></td>
        <td>222</td>
        <td class='lastCell'>Waiting For</td>
      </tr>
      <tr>
        <td>VA</td>
        <td>ARR</td>
        <td><span class='ms-nowrap'>12/8/2018</span></td>
        <td>15</td>
        <td class='lastCell'>Received</td>
      </tr>
    </table>

JS

$(document).ready(function() {
    addTargetClasses();
    checkReceived();
});
(function($) {
    $(function() {
        var orgDates = $('table tr td span');

        var message = '';
        orgDates.each(function(i, elem) {

            parts = $(this).text().split('/');
            dt = new Date(parts[2], parts[0] - 1, parts[1])
                .getTime();
            diffdate = Math.floor((dt - new Date().getTime()) /
                (86400 * 1000));

            if (diffdate === 0 || diffdate === -1) {
                return;
            }
            if (diffdate > 0 || $(this).parents(
                    'tr.targetRow').find('lastCell').hasClass(
                    'crossout')) {
                return;
            }

            if ((diffdate + 2) < 1) {
                if (diffdate.length == 1) {
                    console.log(diffdate);
                }
                if ((diffdate + 2) == 0) {
                    diffdate = (diffdate + 1) + ' day ago';
                } else {
                    diffdate = (diffdate + 1) + ' days ago';
                }
            }

            diffdate = diffdate.toString().slice(1);



            state = $(elem).parents(
                '.targetTable tr.targetRow').find(
                "td:nth-child(2)").text();
            mailType = $(elem).parents(
                '.targetTable tr.targetRow').find(
                " td:nth-child(4)").text();

            message += state + ' ' + mailType + ' was due ' +
                diffdate + '<br/>';
        });

        $.alert({
            theme: "my-theme",

            title: "<span style='font-size:25px;'>" +
                "</span>",
            content: "The following bulk is past the expected received date:" +
                "<br/>" + "<br/>" + message,
            draggable: true,
            animationBounce: 1.5,
            buttons: {
                Dismiss: function() {}
            }
        });

        $('span[title*="Bulk Tracking"]').after(
            "<button id='alert_btn' type='button'>See Alerts</button>"
        );
        $('#alert_btn').after(
            '<div id="emmacontainer" class="emmacontainer"><div class="container__inner"><div class="subDiv"></div> </div></div>'
        );

        $('.subDiv').append(message);

        $('#emmacontainer').hide();
        $('#alert_btn').click(function() {
            $('#emmacontainer').slideToggle(400);
        });


    })
})
(jQuery);

function addTargetClasses() {
    $("table[summary*='Bulk'] ").addClass("targetTable");
    $(".targetTable tr").addClass("targetRow");
}

function checkReceived() {
    $('.targetTable td.lastCell:contains("Received")').addClass('crossout');
};

The above code works as intended. I loops through the dates in the table, checks whether or not they are past due, and outputs a string with the correlating data. The problem is when there are a lots of items overdue the text inside the alert and button div become way too long. So I was hoping to group dates that are the same together to save some space. For example, instead of this:

  • IL NR was due 13 days ago

  • TX FT was due 5 days ago

  • MT NR was due 7 days ago

  • AK LR was due 7 days ago

  • VA ARR was due 6 days ago

I would like it to read like this:

  • IL NR was due 13 days ago

  • TX FT was due 5 days ago

  • MT NR, AK LR were due 7 days ago

  • VA ARR was due 6 days ago

I have tried to iterate over the diffdate var and the $elem from the each loop but I never get what I expected as the output. I am relatively new to js and jquery so any help or advise would be much appreciated!