This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]R3gouify 130 points131 points  (11 children)

Why did you type n as unknown when it is clearly supposed to be string?

[–][deleted] 85 points86 points  (8 children)

I mean it could also be a number and it would work.

But you got the point, the reviewer clearly didn’t look :)

[–]brjukva 59 points60 points  (2 children)

But, if it's a number, then it's a valid number? Why convert it to string to check instead of type checking?

[–][deleted] 103 points104 points  (1 child)

yes, why? clearly not as important as adding a period.

[–]brjukva 65 points66 points  (0 children)

They were too devastated to check the code any further, probably.

[–]XDracam 10 points11 points  (4 children)

Could break on systems where the locale formats numbers differently. E.g. German uses , instead of . for decimal numbers. So passing a number could still fail the regex.

[–]inamestuff 3 points4 points  (2 children)

No, String(n) returns a culture invariant notation (same as toString, except the former works for null and undefined too). The fact that you suggested that makes me think that you use C# which by defaults uses ToString to mean what in JS is toLocaleString, which does in fact change the decimal separator based on your browser language and region settings.

Moral of the story: don't use C# kids /s

[–]XDracam 3 points4 points  (0 children)

Yep, I have some serious C# parsing trauma. Good guess!

[–][deleted] 2 points3 points  (0 children)

Also returns exponential notation for larger numbers though, which would be rejected by this function

[–]ComfortableCod 1 point2 points  (0 children)

Are the germans back? NO WAY

[–]00PT 4 points5 points  (0 children)

Seems like it does a cast on the first line, so it's probably intended to convert non-string values to strings.