]> git.za3k.com Git - za3k.git/commitdiff
Support non-numbers
authorZachary Vance <za3k@za3k.com>
Sun, 15 May 2016 17:39:45 +0000 (10:39 -0700)
committerZachary Vance <za3k@za3k.com>
Sun, 15 May 2016 17:39:45 +0000 (10:39 -0700)
eval.html

index 8b63adcd4c704a57722529983dc1ca51f3bfefbd..b4bd280ccc1e355373937835f3faad4610ffd6f0 100644 (file)
--- a/eval.html
+++ b/eval.html
@@ -5,7 +5,7 @@
 <script>
 
 function arg_names(f) {
-   return f.toString ().match (/function\s*\w*\s*\((.*?)\)/)[1].split (/\s*,\s*/);
+   return _.compact(f.toString ().match (/function\s*\w*\s*\((.*?)\)/)[1].split (/\s*,\s*/));
 }
 
 var params = {};
@@ -33,9 +33,11 @@ function change_parameters(new_args) {
 function load_inputs() {
     _.each(args, function(arg) {
         var arg_value = $("#inputs input[name=" + arg + "]").val();
-        arg_value = Number.parseFloat(arg_value);
-        if (_.isNaN(arg_value)) {
+        var num_value = Number(arg_value);
+        if (arg_value === "" || _.isUndefined(arg_value)) {
           arg_value = undefined;
+        } else if (!_.isNaN(num_value) && parseFloat(arg_value)==num_value) {
+          arg_value = num_value;
         }
         params[arg] = arg_value;
     });
@@ -132,6 +134,8 @@ label {
 </head>
 <body>
 <div class="definition"><label>Function</label><pre id="formula" contenteditable="true">
+// Javascript
+// Edit me and change my arguments!
 function(r, h) {
     return Math.PI * Math.pow(r, 2) * h;
 }