Skip to content

Instantly share code, notes, and snippets.

@fleepgeek
Last active January 29, 2019 15:43
Show Gist options
  • Save fleepgeek/acf61e5b1e4ea6e78bc171d919708705 to your computer and use it in GitHub Desktop.
Save fleepgeek/acf61e5b1e4ea6e78bc171d919708705 to your computer and use it in GitHub Desktop.
A JavaScript function to check if a given number is an Armstrong number
function isArmstrong(num){
var numStr = num.toString();
var isArmstrongNum = false;
var sum = 0;
if(numStr.length === 3){
for(var i=0; i < numStr.length; i++) {
var n = parseInt(numStr.charAt(i));
sum += Math.pow(n, 3);
}
if(sum === num) {
isArmstrongNum = true;
}
}
return isArmstrongNum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment