3 ms·
One would assume it to be equivalent to (written in the most old style possible way so everybody can understand it) ['1', '7', '11'].map(function(n) {return
by pmontra 6y ago
One would assume it to be equivalent to (written in the most old style possible way so everybody can understand it)
['1', '7', '11'].map(function(n) {return parseInt(n);})
but no, map has got an extra argument, the index of the array
function traceParseInt(n, i) {
console.log(i);
return parseInt(n, i);
}
['1', '7', '11'].map(traceParseInt)
0
1
2
[ 1, NaN, 3 ]
Nice way to wait for an integration test to complete. Thanks.
- erichocean 6y agoAnd parseInt() also take an extra argument, the "base" of the number—hence the weird results. (Which also means that a static type checker would not have caught this "bug".)