You need to know how many times the phrase (a delay of more than 15 minutes) will be a multiple of 3.
For example, in my code this phrase is found (being more than 15 minutes late) 6 times in the condition I have written that if a number is, for example, 6 == 3, that is, a multiple of 3, then there is a counter that counts the number of times this phrase is multiple, it turns out 2- (6 / 3 = 2).

The problem is that the user can change the lines, namely, to change the phrase (not agreed) for agreed and it turns out that if the delay is agreed then the repeating phrases will not be 6 but 5 because if a delay of more than 15 minutes is agreed == It is agreed that this phrase is roughly subtracted. And it turns out that in the condition we will have 5 == 3, that is, not a multiple of 3 and will be 1 - (5/3 = 1 (if rounded without a residue)).

I do not have enough logic to come up with so that if the phrases were not an even number, then the values ​​would be considered.

var k = 0; jQuery(function($) { //console.log(add()); }); function add() { $('table tr').each(function(row, e) { var col1 = $(e).children('td:nth-child(4)').text(); var col2 = $(e).children('td:nth-child(5)').text(); if (col1 == 'ΠΎΠΏΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π±ΠΎΠ»Π΅Π΅ 15ΠΌΠΈΠ½' && col2 == 'согласовано') { // console.log(col1, col2); return ++k; } }); } add(); //$('span.r1').text('ΠŸΠΎΠ·ΠΈΡ†ΠΈΠΉ согласовано: ' + k); //Π‘Ρ‡Π΅Ρ‚Ρ‡ΠΈΠΊΠΈ для ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ Π²Π½ΡƒΡ‚Ρ€ΠΈ Ρ†ΠΈΠΊΠ»Π° var razCounter = 0; var dvaCounter = 0; //Π‘Ρ‡Π΅Ρ‚Ρ‡ΠΈΠΊΠΈ для присваивания Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π° var razResultCounter = 0; var dvaResultCounter = 0; //Π’Ρ‹Π±ΠΎΡ€ΠΊΠ° всСх ячССк Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ с ΠΊΠΎΠ½Ρ‚Π΅Π½Ρ‚ΠΎΠΌ var razArray = document.querySelectorAll("table td"); //ΠŸΠ΅Ρ€Π΅Π±ΠΎΡ€ ячССк for (var i = 0; razArray.length > i; i++) { var currentContent = razArray[i].innerHTML; if (currentContent == "ΠΎΠΏΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π±ΠΎΠ»Π΅Π΅ 15ΠΌΠΈΠ½") { razCounter++; if (razCounter == 3) { razResultCounter++; razCounter = 0; } } else if (currentContent == "ΠΎΠΏΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠ΅Π½Π΅Π΅ 15ΠΌΠΈΠ½") { dvaCounter++; if (dvaCounter == 3) { dvaResultCounter++; dvaCounter = 0; } } } $('span.t').text("Π‘ΠΎΠ»Π΅Π΅ 15 ΠΌΠΈΠ½ ΠΊΡ€Π°Ρ‚Π½Ρ‹ числу 3 : " + razResultCounter); // Π­Ρ‚ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π²Π°ΠΆΠ½ΠΎ для расчСта, Ρ‚ΡƒΡ‚ показываСтся число ΠΊΡ€Π°Ρ‚Π½ΠΎΠ΅ 3 $('span.t1').text("МСнСС 15 ΠΌΠΈΠ½: ΠΊΡ€Π°Ρ‚Π½Ρ‹ числу 3: " + dvaResultCounter); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table border="1" width="1020" cellspacing="0" cellpadding="0"> <tbody> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС мСнСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС мСнСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> <td width="230">опозданиС болСС 15мин</td> <td width="140">нС согласовано</td> </tr> <tr> </tbody> </table> <span class="t"></span> <br> <span class="t1"></span> <br> <span class="r1"></span> 

  • one
    You can count the number of entries "delayed more" and "delayed less" for any number of records? Your logic of multiplicity can be replaced by integer division. - br3t
  • @ br3t, this code counts the number of entries in the table. My brain just exploded to solve this problem. It seems like it is not difficult, but I can not find a solution myself. - Eliot
  • 3
    Comparison of text strings in the application logic will not lead to good. On the server side, determine which lines are less late, which are larger, which are consistent, and which are not. and tag them with the appropriate data- attributes. Then work with attributes, otherwise when you turn into 15 minutes at 10, damn that day when you wrote this code, especially if you have a lot of it. I have advised you this last time in my opinion. - teran
  • @teran, say it right. The deadlines for the project are simply very tight and for the time being I will leave it like this, but I undertake to redo it. - Eliot
  • 2
    catch can help what. - teran

1 answer 1

In general, your formula will be something like this:

 сounter = Math.floor(lines/3); 

where lines are the number of your entries,

counter is your multiplicity

  • I stumbled upon this already in the process of solving it, but how can I connect it with my code, what was working correctly, will you help to implement it in JS code? I'm just not special as a novice and I try to figure it out myself. But as you can see, I know the solutions, but I don’t fully realize it myself due to lack of experience. - Eliot
  • one
    Look, does this jsfiddle.net/br3t/ufgp9ec4 code work correctly? - br3t
  • one
    Error text can copy? At the same time console.log(add()) - br3t
  • one
    So you add lost - br3t
  • one