CodeWars 6kyu. Playing with digits

CodeWars 6kyu. Playing with digits

CodeWars 6kyu. Playing with digits

Play with digits 😊

I changed the type of input n to cycle through each digit.

1
2
3
4
5
6
7
8
9
function digPow(n, p){
let digitSum = 0;
let strNum = String(n);
for(let i in strNum){
digitSum += strNum[i]**p;
p++;
}
return Number.isInteger(digitSum/n) ? digitSum/n : -1;
}

Submit screen

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×