テーブルを弄る?

http://oshiete.goo.ne.jp/qa/6234024.html

書いてみました。しかも補集合を追加!ソートは無理!

<!DOCTYPE html>
<title></title>

<table border="1" id="hoge">
  <thead>
    <tr>
      <th>No
      <th>Prefecture
      <th>Cities
      <th>Comments
  </thead>
  
  <tbody>
    <tr>
      <td>1
      <td>岩手県
      <td>洋野町
      <td>ウニがおいしい
      
    <tr>
      <td>2
      <td>青森県
      <td>八戸市
      <td>イカがおいしい
    
    <tr>
      <td>3
      <td>岩手県
      <td>久慈市
      <td>美しすぎる海女さんで、おしい
    
    <tr>
      <td>4
      <td>青森県
      <td>八戸市
      <td>美しすぎる市議会議員で、さわがしい

    <tr>
      <td>5
      <td>岩手県
      <td>洋野町
      <td>鮑がおいしい
      
    <tr>
      <td>6
      <td>青森県
      <td>八戸市
      <td>B級グルメ「せんべい汁」がおいしい
    
    <tr>
      <td>7
      <td>岩手県
      <td>洋野町
      <td>天然ホヤがおいしい
    
  </tbody>
</table>


<script type="application/javascript; version=1.8">
(function () {
  
  var filter =
    (function (tr)
      function (cbObj) {
        Array.forEach (this.tBodies, tr, cbObj);
        return this;
      })
    (function (tbody) Array.forEach (tbody.rows, this.func, this));
  
  
  function TableViewer (node) {
    this.table = node;
  }

  var reset =
    (function (disp)
      function () {
        filter.call (this.table, { func: disp });
        return this;
      })(function (tr) tr.style.display = 'table-row');


  var limit =
    (function (tr)
      function (n) {
        filter.call (this.table, { func: tr, count: n || 0 });
        return this;
      })

    (function (tr) {
      if (tr.style.display !== 'none')
        if (0 < this.count) {
          tr.style.display = 'table-row';
          this.count--;
        }
        else 
          tr.style.display = 'none';
     });
  
  var reverce =
    (function (rev)
      function () {
        filter.call (this.table, { func: rev });
        return this;
      })(function (tr)
        let (s = tr.style)
          s.display = 'table-row' === s.display ? 'none': 'table-row');
    
  
  var find =
    (function (tr)
      function (reg, index) {
        filter.call (this.table, { func: tr, regExp: reg, cellIndex: index });
        return this;
      }
    )(function (tr)
        let (s = tr.style)
        let (t = ('undefined' === typeof this.cellIndex ? tr: tr.cells[this.cellIndex]).textContent)
          s.display = this.regExp.test (t) ? 'table-row': 'none');
  
  
  function create (tableNode) {
    if ('tagName' in tableNode)
      if ('TABLE' === tableNode.tagName)
        return new TableViewer (tableNode);
  };

  TableViewer.prototype.reverce = reverce;
  TableViewer.prototype.reset = reset;
  TableViewer.prototype.limit = limit;
  TableViewer.prototype.find = find;

  this.createTableViewer = create;
})();

var table = createTableViewer (document.getElementById ('hoge'));
table.reset ().find (/お.*しい/, 3).limit (5);

</script>