Skip to content

Instantly share code, notes, and snippets.

@pavel-lens
Last active January 3, 2017 18:54
Show Gist options
  • Save pavel-lens/5743af82c60a2af40ec777735dde14a5 to your computer and use it in GitHub Desktop.
Save pavel-lens/5743af82c60a2af40ec777735dde14a5 to your computer and use it in GitHub Desktop.
function sumDigPow(a, b) {
const arr = [];
for (let i = a; i <= b; i++) {
let sum = 0;
for (let j = 0; j <= String(i).length; j++) {
sum += Math.pow(parseInt(String(i)[j]), j+1);
if (sum == i) arr.push(i);
}
}
return arr;
}
console.log(sumDigPow(0, 150)); // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment