File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,14 @@ flags:gmi
77const regexTest = / ( - ? \d { 1 , 3 } (?: \. \d { 1 , 2 } ) ? ) ° ? \s ? (?: d e g r e e s ? ) ? \s ? c (?: e l s i u s ) ? \b / gi;
88const celsiusToFahrenheit = c => ( ( c * 9 / 5 ) + 32 ) . toFixed ( 2 ) ;
99const formatNumber = num => Number ( num ) . toFixed ( 2 ) . replace ( / \. 0 0 $ / , '' ) ;
10- const conversions = [ ] ;
10+ const conversions = [ ] ; ,
1111
12- current . text = current . text . replace ( regexTest , ( match , c ) => {
13- const fahrenheit = celsiusToFahrenheit ( c ) ;
14- const formattedC = formatNumber ( c ) ;
15- conversions . push ( ` ${ formattedC } °C is ${ fahrenheit } degrees in freedom units (Fahrenheit).` ) ;
16- return `${ fahrenheit } °F` ;
17- } ) ;
12+ let match ;
13+ while ( ( match = regexTest . exec ( current . text ) ) !== null ) {
14+ const celsius = parseFloat ( match ) ;
15+ const fahrenheit = celsiusToFahrenheit ( celsius ) ;
16+ conversions . push ( `${ formatNumber ( celsius ) } °C is ${ formatNumber ( fahrenheit ) } degrees in sane units (Fahrenheit).` ) ;
17+ }
1818
1919const conversionMessage = conversions . join ( '\n' ) ;
2020
You can’t perform that action at this time.
0 commit comments