title: Sort empty or null to bottom always
body: <p>The following is a natural sort function I pulled from somewhere I forget exactly.  I'm looking to modify it so that empty or null values always sort to the bottom regardless of asc/desc.</p>
  
  <p>Here is what I have right now:</p>
  
  <pre><code>function gridNaturalSorter(a, b) {      
      if(a[sortcol])
          a = a[sortcol].replace(/&lt;(?:.|\n)*?&gt;/gm, '');
      if(b[sortcol]) 
          b = b[sortcol].replace(/&lt;(?:.|\n)*?&gt;/gm, '');
  
      if(b)
          b = b.toString().substr(0, 15);
      if(a)
          a = a.toString().substr(0, 15);
  
      var re = /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi, 
          sre = /(^[ ]*|[ ]*$)/g,
          dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
          hre = /^0x[0-9a-f]+$/i,
          ore = /^0/,
          i = function(s) { 
              return gridNaturalSorter.insensitive &amp;&amp; (''+s).toLowerCase() || ''+s 
          },
  
          // convert all to strings strip whitespace
          x = i(a).replace(sre, '') || '',
          y = i(b).replace(sre, '') || '',
  
          // chunk/tokenize
  
          xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
          yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
  
          // numeric, hex or date detection
  
          xD = parseInt(x.match(hre)) || (xN.length != 1 &amp;&amp; x.match(dre) &amp;&amp; Date.parse(x)),
          yD = parseInt(y.match(hre)) || xD &amp;&amp; y.match(dre) &amp;&amp; Date.parse(y) || null,
          oFxNcL, oFyNcL;
  
          // first try and sort Hex codes or Dates
          if (yD)
              if ( xD &lt; yD ) return -1;
          else if ( xD &gt; yD ) return 1;
  
          // natural sorting through split numeric strings and default strings
          for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc &lt; numS; cLoc++) {
              // find floats not starting with '0', string or 0 if not defined (Clint Priest)
              oFxNcL = !(xN[cLoc] || '').match(ore) &amp;&amp; parseFloat(xN[cLoc]) || xN[cLoc] || 0;
              oFyNcL = !(yN[cLoc] || '').match(ore) &amp;&amp; parseFloat(yN[cLoc]) || yN[cLoc] || 0;
  
              // handle numeric vs string comparison - number &lt; string - (Kyle Adams)
              if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { 
                  return (isNaN(oFxNcL)) ? 1 : -1; 
              }
              // rely on string comparison if different types - i.e. '02' &lt; 2 != '02' &lt; '2'
              else if (typeof oFxNcL !== typeof oFyNcL) {
                  oFxNcL += '';
                  oFyNcL += '';
              }
              if (oFxNcL &lt; oFyNcL) 
                  return -1;
              if (oFxNcL &gt; oFyNcL) 
                  return 1;
          }
      return 0;
  }
  </code></pre>