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
// Function to check if a number is an Armstrong number | |
function isArmstrong(number) { | |
// Convert the number to a string to determine its length | |
let numStr = String(number); | |
let numDigits = numStr.length; | |
// Calculate the sum of the digits raised to the power of the number of digits | |
let sumOfDigits = numStr.split('').reduce((sum, digit) => sum + Math.pow(parseInt(digit), numDigits), 0); | |
// Check if the sum is equal to the original number |