Javascript issue

Imagine i have a table with these values:

Date(Column) Hours(Column)
01.07.2010 9
03.07.2010 9

In this table you would have noticed that there are Hours value available for dates 01 and 03. But for 02 it is not there. How will i use javascript and get to know the date that is not present in this table. I need to know the missing date. can anyone help me with the logic?

You didn’t tell me the same date could occur more than once! :frowning:

var rows = document.getElementById("hours").rows, day = 0, missing = [], d;
for (var i = 0; i < rows.length; ++i) {
    d = parseInt(/^(\\d+)/.exec(rows[i].cells[0].firstChild.data)[1], 10);
    while (d > ++day) {
        missing.push(day);
    }
    day = d;
}
alert("Missing days: " + missing.join(", "));

This logic is fine. But in the table if we have 2 entries or 2 hour values for the same date. Then the count incrementation wont work fine.

You asked for the logic, not the details, but okay.

Assuming the following table,

<table>
  <thead>
    <tr>
      <th>Date</th>
      <th>Hours</th>
    </tr>
  </thead>
  <tbody id="hours">
    <tr>
      <td>01.07.2010</td>
      <td>9</td>
    </tr>
    <tr>
      <td>03.07.2010</td>
      <td>9</td>
    </tr>
  </tbody>
</table>

this code would show the missing date(s):

var rows = document.getElementById("hours").rows, day = 0, missing = [], d;
for (var i = 0; i < rows.length; ++i) {
    d = parseInt(/^(\\d+)/.exec(rows[i].cells[0].firstChild.data)[1], 10);
    while (d > ++day) {
        missing.push(day);
    }
}
alert("Missing days: " + missing.join(", "));

Im supposed to do it in javascript only. As it is a tool where u have to use javascript to do some functionalities. do you know the solution to solve this problem?

Thanks AutisticCuckoo. Could u please write this code and post it here. I am a beginner in javascript so I am not sure how to implement it codewise. Hoping to hear from you soon

Initialise a counter variable to 0.
Loop over each table row.
For each row, extract the date part from the first cell.
Increment the counter variable.
While the date value > the counter variable, add the counter value to an array and increment the variable.

Afterwards you’ll have an array containing the dates that aren’t present in the table.

Are you sure Javascript is the best solution and not do it server-side in PHP/ASP/Python/and so on?