I was resolving some problems on codewars and tried to convert a string to a list of numbers like this:
"102904".split("").map(parseInt);
The expected result would be something like this:
[1, 0, 2, 9, 0, 4]
But it returns instead:
[1, NaN, NaN, NaN, 0, 4]
At believe that map should apply to each element in the list which are strings of 1 digits. One could believe that it isn't parsing correctly because the base isn't used but:
"102904".split("").map(function(x){ return parseInt(x);});
[ 1, 0, 2, 9, 0, 4]
Using parseInt(x, 10)
, doesn't change the result. But sending directly parseInt to map creates NaN
...
I tried on Chrome and Firefox and I receive the same results.