Inverse table search

I have a table search but I would like to make an inverse search. In my jQuery code how can I exchange .hide() -> .show() and .show() -> .hide() when a <input type="checkbox" checked> is false. And when checkbox is checked undo everything.

<input type="text" placeholder="Search..." id="search_field">
<input type="checkbox" checked>
<table id="myTable" border="1">
    <thead>
        <tr class="myHead">
            <th>XDFFD</th>
            <th>DFDDY</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
        <tr>
            <td>5</td>
            <td>6</td>
        </tr>
    </tbody>
</table>

    $('#search_field').on('keyup', function() {
        var value = $(this).val();
        var patt = new RegExp(value, "i");
        $('#myTable').find('tr').each(function() {
            if (!($(this).find('td').text().search(patt) >= 0)) {
                $(this).not('.myHead').hide();
            }
            if (($(this).find('td').text().search(patt) >= 0)) {
                $(this).show();
            }
        });
    });

Answer

You check if the checkbox is checked or not using is(":checked") this will give true or false so depending on this show or hide trs.

Demo Code :

$('#search_field').on('keyup', function() {
  var value = $(this).val();
  var patt = new RegExp(value, "i");
  var checks = $(".checkbox").is(":checked"); //check if checkbox is checked
  console.log(checks)
  if (value != "") {
    $('#myTable tbody').find('tr').each(function() {
      var condition = $(this).find('td').text().search(patt) >= 0
      //checked
      if (checks) {
        //show and hide..
        condition ? $(this).show() : $(this).hide()
      } else {
        condition ? $(this).hide() : $(this).show()
      }
    });
  } else {
    $('#myTable tbody > tr').show()
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" placeholder="Search..." id="search_field">
<input type="checkbox" class="checkbox" checked>
<table id="myTable" border="1">
  <thead>
    <tr class="myHead">
      <th>XDFFD</th>
      <th>DFDDY</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
    </tr>
    <tr>
      <td>3</td>
      <td>4</td>
    </tr>
    <tr>
      <td>5</td>
      <td>6</td>
    </tr>
  </tbody>
</table>