Last active
July 31, 2016 19:03
-
-
Save sethschori/96e3c54efc6f9676b2bd66628ff603ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Power Up! | |
Create a function powerUp() that takes an integer as input. It should return a new number, created by summing each digit raised by a consecutive power | |
ex) | |
powerUp(761) --> 7^1 + 6^2 + 1^3 === 44 | |
powerUp(100) --> 1^1 + 0^2 + 0^3 === 1 | |
*/ | |
function powerUp(num) { | |
num = num.toString(); | |
var sum = 0; | |
for (var i = 0; i < num.length; i++) { | |
sum += Math.pow(Number(num.charAt(i)),i+1); | |
} | |
return sum; | |
} | |
console.log(powerUp(761)); | |
// 7^1 + 6^2 + 1^3 === 44 | |
console.log(powerUp(100)); | |
// 1^1 + 0^2 + 0^3 === 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
44 | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment