File tree Expand file tree Collapse file tree 1 file changed +12
-20
lines changed
Expand file tree Collapse file tree 1 file changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -52,30 +52,22 @@ export const splitChartConfigs = (config: ChartConfigWithOptDateRange) => {
5252 return [ config ] ;
5353} ;
5454
55- export const computeRatio = (
56- numeratorInput : string | number ,
57- denominatorInput : string | number ,
58- ) => {
59- let numerator : number ;
60- let denominator : number ;
61-
62- if ( typeof numeratorInput === 'string' ) {
63- if ( numeratorInput . trim ( ) === '' ) {
55+ const castToNumber = ( value : string | number ) => {
56+ if ( typeof value === 'string' ) {
57+ if ( value . trim ( ) === '' ) {
6458 return NaN ;
6559 }
66- numerator = Number ( numeratorInput ) ;
67- } else {
68- numerator = numeratorInput ;
60+ return Number ( value ) ;
6961 }
62+ return value ;
63+ } ;
7064
71- if ( typeof denominatorInput === 'string' ) {
72- if ( denominatorInput . trim ( ) === '' ) {
73- return NaN ;
74- }
75- denominator = Number ( denominatorInput ) ;
76- } else {
77- denominator = denominatorInput ;
78- }
65+ export const computeRatio = (
66+ numeratorInput : string | number ,
67+ denominatorInput : string | number ,
68+ ) => {
69+ const numerator = castToNumber ( numeratorInput ) ;
70+ const denominator = castToNumber ( denominatorInput ) ;
7971
8072 if ( isNaN ( numerator ) || isNaN ( denominator ) || denominator === 0 ) {
8173 return NaN ;
You can’t perform that action at this time.
0 commit comments