narcissistic number javascript code example
Example: 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));