isArmstrongNumber

Medium · Number Theory · 4 test cases

An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. Write a function to check if a number is an Armstrong number.

Examples

isArmstrongNumber(153) → true
isArmstrongNumber(370) → true
isArmstrongNumber(123) → false

Starter code

function isArmstrongNumber(num) {

}

Complexity of the optimal solution

Time O(d), space O(d). The time complexity is proportional to the number of digits (d) in the number. Converting the number to a string, splitting it, and reducing it are all operations that depend on the number of digits.

Solve isArmstrongNumber in the browser