JS IsNumeric tests

by Nathan Perry

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.0.1/lodash.min.js"></script>
<table class="out compact">
  <tr>
    <th>Method</th>
    <th>Value</th>
    <th>Result</th>
    <th>Result</th>
  </tr>
</table>

CSS

table.compact {
  border: 1px solid #DFDFDF;
  background-color: #F9F9F9;
  width: 100%;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
  font-family: Arial,"Bitstream Vera Sans",Helvetica,Verdana,sans-serif;
  color: #333;
}
table.compact td, #table-3 th {
  border-top-color: white;
  border-bottom: 1px solid #DFDFDF;
  color: #555;
}
table.compact th {
  text-shadow: rgba(255, 255, 255, 0.796875) 0px 1px 0px;
  font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif;
  font-weight: normal;
  padding: 7px 7px 8px;
  text-align: left;
  line-height: 1.3em;
  font-size: 14px;
}
table.compact td {
  font-size: 12px;
  padding: 4px 7px 2px;
  vertical-align: top;
}

JavaScript

"use strict";

var log = function(){ console.log.apply(console, arguments); };

var logTable = function(){
  var args = _.toArray(arguments);
  $('table.out').append("<tr><td>" + args.join("</td><td>") + "</td></tr>")
};

var testValues = function(fn){

  // fn( value, name, expected)
  fn( 1               , "1"               , true  );
  fn( -1              , "-1"              , true  );
  fn( 15.5            , "15.5"            , true  );
  fn( '15.5'          , "'15.5'"          , true  );
  fn( 123             , "123"             , true  );
  fn( '123'           , "'123'"           , true  );
  fn( -123            , "-123"            , true  );
  fn( '-123'          , "'-123'"          , true  );
  fn( +123            , "+123"            , true  );
  fn( '+123'          , "'+123'"          , true  );
  fn( '.123'          , "'.123'"          , true  );
  fn( '-.123'         , "'-.123'"         , true  );
  fn( '0.123'         , "'0.123'"         , true  );
  fn( '-0.123'        , "'-0.123'"        , true  );
  fn( '1e100'         , "'1e100'"         , true  );
  fn( '1e-100'        , "'1e-100'"        , true  );
  fn( '-1e-100'       , "'-1e-100'"       , true  );
  fn( Infinity        , "Infinity"        , true  );
  fn( -Infinity       , "-Infinity"       , true  );
  fn( 'abc'           , "'abc'"           , false );
  fn( '10%'           , "'10%'"           , false );
  fn( '#10'           , "'#10'"           , false );
  fn( '2^10'          , "'2^10'"          , true  );
  fn( '2!'            , "'2!'"            , false );
  fn( '(10)'          , "'(10)'"          , false );
  fn( '10px'          , "'10px'"          , false );
  fn( '*'             , "'*'"             , false );
  fn( ''              , "''"              , false );
  fn( true            , "true"            , false );
  fn( false           , "false"           , false );
  fn( []              , "[]"              , false );
  fn( function(){}    , "function(){}"    , false );
  fn( {}       ...