Created
July 4, 2021 12:37
-
-
Save kharioki/805853dd3a1d1c0c49b1744e09ed9df2 to your computer and use it in GitHub Desktop.
Dig pow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function digPow(n, p){ | |
| const digits = n.toString().split('').map(Number); | |
| let sum = 0; | |
| digits.forEach(digit => { | |
| sum += Math.pow(digit , p); | |
| p++; | |
| }) | |
| return sum % n ? -1 : sum/n; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment