Journal Archive

function solution16(n=2, p=1000) {
   let bigIntNum = BigInt(Math.pow(n, p));

   function sumOfDigits(num) {
      return num.toString().split("")
        .map( digit => +digit)
        .reduce( (digit, tot) => tot + digit, 0);
   }

   return sumOfDigits(bigIntNum);
}

Day 2: Solving one of Project Euler's problems

Power digit sum

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 21000 ?