← Back to challenges

Narcissistic Number

JavaScriptHardlanguage_fundamentalsmathnumberslogicvalidation

Instructions

A Narcissistic Number is a number that is the sum of its own digits each raised to the power of the number of digits.

For example, take 153 (3 digits), which is narcisstic:

1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153

1652 (4 digits), is non-narcisstic:

1^4 + 6^4 + 5^4 + 2^4 = 1 + 1296 + 625 + 16 = 1938

Create a function that returns true or false depending upon whether the given number n is a Narcissistic number or not.

Examples

isNarcissistic(153) ➞ true

isNarcissistic(370) ➞ true

isNarcissistic(1652) ➞ false

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Sum of Even Pairs in Array