1

so, I'm trying to build a function to return an array of digits in an integer. looks something like:

function getDigits(val){
   return val.toString().split('').map(parseInt);
}
getDigits(123456); // [1, NaN, NaN, NaN, NaN, NaN]

but if i do

function getDigits(val){
   return val.toString().split('').map(function(item){
      return parseInt(item);
   });
}
getDigits(123456); // [1, 2, 3, 4, 5, 6]

I'm not interested in knowing if this is a good implementation or not, just to find out why .map is not working as it should on the first time.

André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120

0 Answers0