Created
September 19, 2020 06:45
-
-
Save hassan-maavan/fc521df092ef61e957ca3758ec8e248a to your computer and use it in GitHub Desktop.
A Narcissistic Number is a positive number which is the sum of its own digits, each raised to the power of the number of digits in a given base. In this Kata, we will restrict ourselves to decimal (base 10). https://www.codewars.com/kata/5287e858c6b5a9678200083c
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 narcissistic(value) { | |
let array = value.toString().split(''); | |
let count = array.length; | |
let result = array.map((num) => Math.pow(num, count)); | |
if(eval(result.join(',').replace(/,/g, '+')) == value) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment