Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Narcissistic

//153 = 1^3 + 5^3 + 3^3 = 1+125+27 = 153
//the above line shows the meaning of narcissistic,meaning sum of power of number should be 
//equal to that number 153===153
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;
};
 
PREVIOUS NEXT
Tagged: #Narcissistic
ADD COMMENT
Topic
Name
7+7 =