Why does parseInt give NaN when I am not putting it in an arrow function? What's strange is that only 50 is getting properly parsed, while the others are not... Is there something wrong with putting parseInt itself as an argument? I want to make sure all of them are whole numbers, it works with an arrow function but I would like to know why it doesn't work just passing in the whole function. Even trying to bind it to window with .map(parseInt.bind(window)) doesn't work. Is it a problem with the source code?
function toPercent(array) {
let arr = array.map((a, _, s) => a / s.reduce((a, b) => a+b) * 100)
console.log(arr)
return arr.map(parseInt)
}
console.log(toPercent([2, 1, 1]))
function toPercent(array) {
let arr = array.map((a, _, s) => a / s.reduce((a, b) => a+b) * 100)
console.log(arr)
return arr.map(n => parseInt(n))
}
console.log(toPercent([2, 1, 1]))