Thanks for sharing. But I am so confused about one example.
Alex Yuan


Good remark! It turns out that map() calls the mapping function with more arguments than we expect. The first argument is the element in the array and the second one is the element index. Take a look at the toInt() mapping function:

const numbers = ['1','2','3','4','5','6'];
function toInt(value, index){
console.log(`value: ${value} index: ${index}`);
return parseInt(value, index);
//value: 1 index: 0
//value: 2 index: 1
//value: 3 index: 2
//value: 4 index: 3
//value: 5 index: 4
//value: 6 index: 5

When we call parseInt(value, base) with two arguments, it uses the second argument as the base in mathematical systems. When base is 0, it defaults to the decimal system. Here are a few example of how parseInt() is called.

console.log(parseInt("1", 0)); //1
console.log(parseInt("2", 1)); //NaN
console.log(parseInt("3", 2)); //Nan

I hope it helps.