Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

codewars playing with digits js

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;
  }
 
PREVIOUS NEXT
Tagged: #codewars #playing #digits #js
ADD COMMENT
Topic
Name
4+2 =