I am trying to solve a kata from Codewars but I bumped into a wall. I’ll leave the instructions down below and my code. If anyone can guide me through the answer or simply what is wrong with my code I will kindly appreciate it.
Instructions
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).
For example, take 153 (3 digits), which is narcisstic:
1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
and 1652 (4 digits), which isn’t:
1^4 + 6^4 + 5^4 + 2^4 = 1 + 1296 + 625 + 16 = 1938
My Code
function narcissistic(value) {
let sum = 0;
for(let i = 0; i < value.length; i++){
sum += Math.pow(value[i], 3);
if(sum == value){
return true;
}
return false;
}
}