DEV Community

loading...

Discussion on: Narcissistic number

Collapse
kepta profile image
Kushan Joshi

Here's my little code golf in javascript.

const digit_pow = (n, pow = n.toString().length, sum = 0) =>
  n ? digit_pow(Math.floor(n / 10), pow, sum + (n % 10) ** pow) : sum;

for (let i = 0; i < 1e6; i++) {
  if (digit_pow(i) === i) console.log(i);
}