Answers for "Javascript Narcissistic Number"

0

Javascript Narcissistic Number

const isNarcissistic = (num) => {
   let m = 1, count = 0;
   while(num / m > 1){
      m *= 10;
      count++;
   };
   let sum = 0, temp = num;
   while(temp){
      sum += Math.pow(temp % 10, count);
      temp = Math.floor(temp / 10);
   };
   return sum === num;
};
console.log(isNarcissistic(153));
console.log(isNarcissistic(1634));
console.log(isNarcissistic(1433));
console.log(isNarcissistic(342));
Posted by: Guest on May-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language