Skip to content

Instantly share code, notes, and snippets.

@hassan-maavan
Created September 19, 2020 06:45
Show Gist options
  • Save hassan-maavan/fc521df092ef61e957ca3758ec8e248a to your computer and use it in GitHub Desktop.
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
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