when I tested the code below .. it returned an error “expected undefined to equal 1” please tell me where is the issue.
const digPow = (n, p) => {
let k;
n = n < 0 ? -n : n;
p = p < 0 ? -p : p;
let splittedStr = n.toString().split('');
let result = splittedStr
.map(digit => Math.pow(digit, p++))
.reduce((curr, prev) => curr + prev, 0);
k = (result / n) % 1 === 0 ? result / n : -1;
console.log(parseInt(result), k);
};
digPow(89, 1);
digPow(92, 1);
digPow(695, 2);
digPow(46288, 3);