News for hackers. Stuff that matters.
Re:Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in... by happytoexplain on Friday June 21, 2019 @11:35AM (#20243409)
I've developed applications in JS, but don't have extensive experience with it, and I couldn't spot the problem. Frankly, I think if `['1', '2'].map(parseInt)` is both valid and does not result in a collection containing the integers 1 and 2 in that order, that indicates a catastrophic failure of design at some level. These things happen, but usually you have to dig down to a less bog standard example to find it. The "you just have to know" argument is often unavoidably valid, but in this case I think it's way off the mark.
Re:Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in... by lucideer on Friday June 21, 2019 @11:40AM (#20243463)
The problem is that this article is attributing this problem to JS, whereas the problem is with either computer science or human decimal bias: i.e. the radix is not a concept invented by JS.

If you think it should be ok for all devs to believe that parseInt === parseDecimalInt then maybe all languages should be decimal-only. That isn't the case though.

Re:Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in... by sixstringtheory on Friday June 21, 2019 @11:59AM (#20243675)
All languages I know of _default_ to a radix of 10 though, allowing other radixes where a prefix is added like 0b111010, 0xa7b45fd9, etc.

Seems intuitive that if parseInt allows omitting the radix parameter, that it should default to whatever radix a standard integer primitive would default to.

Re:Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in... by ianjsikes on Friday June 21, 2019 @12:18PM (#20243867)
> Seems intuitive that if parseInt allows omitting the radix parameter, that it should default to whatever radix a standard integer primitive would default to.

But in this case, the radix is _not_ omitted. The map function passes the index of the current iteration as the second parameter to the function it is passed. It is kinda like this: ``` ['1','7','11'].map((item, index) => parseInt(item, index))

Re:Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in... by sixstringtheory on Friday June 21, 2019 @01:21PM (#20244536)
Thanks for connecting the dots for me, I see it now!