["10","10","10"].map(parseInt)
? ["10","10","10"].map(parseInt)
?You have to do `['10', '10', '10'].map((val) => parseInt(val, 10));` to get the "expected" output. In addition, you should always provide `base` to `parseInt` otherwise it has it's own interpretation infered by the value you give it.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
['10', '10', '10'].map(val => parseInt(val))
Leading zeroes can often be considered invalid input, and you may be able to safely assume that it has been dealt with already.Also the parens around a single argument of an arrow function are a superstitious thing suggested by some well-known react developer a while back, I think.
The extra parentheses is just habit from Prettier formatting :)
['07', '08', '09'].map(val => parseInt(val)) // => [7, 0, 0]
['07', '08', '09'].map(val => parseInt(val)) // => [7, 8, 9]
Another question that I like is asking to find out issues in one fragment of code. This fragment is crafted to contain style issues, some bugs and architecture issues. This allows to understand the level of candidate: which issues can he spot. Not ideal, but I think it works good enough.
You can try ["10","10","10"].map(console.log) for more info... the third argument is the source array:
> 10 0 ['10', '10', '10']
> 10 1 ['10', '10', '10']
> 10 2 ['10', '10', '10']Click the 'Run' button:
https://www.typescriptlang.org/play?#code/MYewdgziA2CmB00QHM...
But yeah it is just a case of the map providing 3 args to the function (element, index, array) and parseInt using 2 value s (string, radix) so we have element->string (yay!) and index->radix (oof!) and array->ignored (meh!)
`Array.map` function API was badly designed. I'd like to know who I should to blame for that design.