There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

418teapot ,

It’s kind of insane how bad this whole is-number thing is. It’s designed to tell you if a string is numeric, but I would argue if you’re ever using that you have a fundamental design problem. I hate dynamic typing as much as anyone else, but if forced to use it I would at least try to have some resemblance of sanity by just normalizing it to an actual number first.

Just fucking do this…


<span style="font-weight:bold;color:#a71d5d;">const </span><span style="font-weight:bold;color:#795da3;">toRegexRange </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">(minStr, maxStr, options) </span><span style="font-weight:bold;color:#a71d5d;">=> </span><span style="color:#323232;">{
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">min </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">parseInt</span><span style="color:#323232;">(minStr, </span><span style="color:#0086b3;">10</span><span style="color:#323232;">);
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">max </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">parseInt</span><span style="color:#323232;">(maxStr, </span><span style="color:#0086b3;">10</span><span style="color:#323232;">);
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">(</span><span style="color:#0086b3;">isNaN</span><span style="color:#323232;">(min) </span><span style="font-weight:bold;color:#a71d5d;">|| </span><span style="color:#0086b3;">isNaN</span><span style="color:#323232;">(max)) </span><span style="font-weight:bold;color:#a71d5d;">throw </span><span style="color:#323232;">Error(</span><span style="color:#183691;">"bad input or whatever"</span><span style="color:#323232;">);
</span><span style="color:#323232;">  </span><span style="font-style:italic;color:#969896;">// ...
</span>

Because of the insanity of keeping them strings and only attempting to validate them (poorly) up front you open yourself up to a suite of bugs. For example, it took me all of 5 minutes to find this bug:


<span style="color:#323232;">toRegexRange(</span><span style="color:#183691;">'+1'</span><span style="color:#323232;">, </span><span style="color:#183691;">'+2'</span><span style="color:#323232;">)
</span><span style="font-style:italic;color:#969896;">// returns "(?:+1|+2)" which is not valid regexp
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines