File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,26 @@ export default function parseInput(input) {
1919 input . match ( / \- ? \d + \. \d + / )
2020 && input . match ( / \- ? \d + \. \d + / ) [ 0 ] === input
2121 ) {
22- //integer
22+ //float
2323 return formatResponse ( 'float' , parseFloat ( input ) ) ;
24+ } else if (
25+ input . match ( / \- ? \d + e - \d + / )
26+ && input . match ( / \- ? \d + e - \d + / ) [ 0 ] === input
27+ ) {
28+ //scientific float
29+ return formatResponse ( 'float' , Number ( input ) ) ;
2430 } else if (
2531 input . match ( / \- ? \d + / )
2632 && input . match ( / \- ? \d + / ) [ 0 ] === input
2733 ) {
28- //float
34+ //integer
2935 return formatResponse ( 'integer' , parseInt ( input ) ) ;
36+ } else if (
37+ input . match ( / \- ? \d + e \+ \d + / )
38+ && input . match ( / \- ? \d + e \+ \d + / ) [ 0 ] === input
39+ ) {
40+ //scientific integer
41+ return formatResponse ( 'integer' , Number ( input ) ) ;
3042 }
3143 } catch ( e ) {
3244 // no-op
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ describe("parseInput", function() {
2020 expect ( parseInput ( "5.22" ) . type ) . to . equal ( "float" )
2121 } )
2222
23+ it ( "parseInput small float" , function ( ) {
24+ expect ( parseInput ( "0.0000002" ) . type ) . to . equal ( "float" )
25+ } )
26+
27+ it ( "parseInput scientific notation float" , function ( ) {
28+ expect ( parseInput ( "2e-7" ) . type ) . to . equal ( "float" )
29+ } )
30+
2331 it ( "parseInput date" , function ( ) {
2432 expect ( parseInput ( "5/22" ) . type ) . to . equal ( "date" )
2533 } )
@@ -28,6 +36,10 @@ describe("parseInput", function() {
2836 expect ( parseInput ( "22" ) . type ) . to . equal ( "integer" )
2937 } )
3038
39+ it ( "parseInput scientific notation integer" , function ( ) {
40+ expect ( parseInput ( "4e+8" ) . type ) . to . equal ( "integer" )
41+ } )
42+
3143 it ( "parseInput NaN" , function ( ) {
3244 expect ( parseInput ( "nan" ) . type ) . to . equal ( "nan" )
3345
You can’t perform that action at this time.
0 commit comments