Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass function to map

Why aren’t the two following statements equivalent:

const output1 = [..."123"].map(parseInt);
const output2 = [..."123"].map(e => parseInt(e));

console.log(output1);
console.log(output2);

What concept am I missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

map will pass the index it is currently looking at as the second argument to the callback function.

parseInt takes an optional second argument which sets the radix (number base) it is parsing from.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading