DEV Community

Discussion on: Mapping Arrays Like A Pro

Collapse
 
fetishlace profile image
fetishlace

Hi there:-) I think that that implicit argument passing to map function call is problem itself in any other case except when function is taking only one argument.
It sounds like parseInt is the problem, but that implicit passing of index is making confusion, since ['1', '2', '-1', '0'].map(x=>Number.parseInt(x)); is explicit, so more readable and working as intended here.
Then it leads to this part:
"With the help of Array.fill() and String.fromCharCode method, we can map all the charCodes in an array."
which is wrong or dirty or confusing at least, since we are not mapping array values = charCodes to strings, but we are doing String.fromCharCode(value, index, array) - so getting concat of strings String.fromCharCode(value) + String.fromCharCode(index) + String.fromCharCode(array) and that last array part is returning " ".
If it is saying we are mapping charCodes to strings (array values), it is not true.
new Array(100).fill(1).map(x=>String.fromCharCode(x)) is what was said.
Else i like playing with JS, just that middle part should be like base for the article about why to avoid implicit argument passing in map function:-)