CodeSOD: A Percise Parser
thedailywtf.com·1d
🔗Parser Combinators
Preview
Report Post

Thomas worked for a company based in Germany which was looking to expand internationally. Once they started servicing other locales, things started to break. It didn’t take long to track the problem down to a very "percise" numeric parser.

handleInput( value ){
let value_ = value;
if( value.substring( 0, 1 ) === '+' ){
value_ = value.substring( 1 );
}

value_ = value_.split( '.' ).join( '' );

if( this.usePercisionIfPercentage && value_.indexOf( ',' ) >= 0 ) {
const parsedPreValue = value_.split( ',' )[ 0 ];
const parsedCommaValue = parseInt( value_.split( ',' )[ 1 ], 10 ) < 10 ?
parseInt( value_.split( ',' )[ 1 ], 10 ) * 10 : value_.split( ',' )[ 1 ].substring( 0, 2 );

if( parsedCommaValue === 0 ) {
value_ = parseInt( parsedPreValue, 10 );
}
else {
const parsedValue = pars...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help