- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Edit Admin
The same way it happens anywhere: one misstep at a time.
Admin
Performance is obviously not a thing, because they're calling
value_.split( ',' )three times, and usingvalue_.split( ',' )[1] twice. They're also potentially callingparseInt( value_.split( ',' )[ 1 ], 10 )twice. (They also could have used the result ofvalue_.indexOf( ',' )` instead of splitting...)And
parsedCommaValueis a number if it's < 9, otherwise it's a string.Admin
Performance is obviously not a thing given that they are using javascript.
Admin
There's the language being slow, and then there's writing a slow algorithm in that language. This is the latter, it would be slow in any language, if you could write it at all without triggering a type error. That "string or int" thing can't be helping performance either, subsequent code cannot use fast paths that rely on knowing the real type.
Edit Admin
Sorry, that was as far as I got before I bailed.
Addendum 2026-02-03 09:07:
Edit Admin
In addition to all the other sins,
handleInputis a really vague name for a number-parsing function.Admin
My favourite part is the parseInt on the decimal part getting rid of leading zeroes, so e.g. '2,04' turns into 2.4.
Edit Admin
Performance is not an issue because they're dealing with user input, typed one character at a time, into a textbox with no more than, say, 20 characters. N is so small that they could have an 2^n algorithm and almost be fast enough to not be noticed by the user.