CodeWars 6kyu. Playing with digits
2019년에 Hexo 블로그에 쓴 글을 옮겨 왔습니다. 당시 이해를 그대로 두었습니다.
CodeWars 6kyu. Playing with digits
Play with digits 😊
I changed the type of input n to cycle through each digit.
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;
}
