We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9a11e1 commit 5a293e3Copy full SHA for 5a293e3
math/armstrong/isarmstrong.go
@@ -19,18 +19,13 @@ func IsArmstrong(number int) bool {
19
// to get the number of digits in the number
20
length := float64(len(strconv.Itoa(number)))
21
22
- // get the right most digit
23
- for {
+ // get the right most digit and break the loop once all digits are iterated
+ for tempNum > 0 {
24
rightMost = tempNum % 10
25
sum += int(math.Pow(float64(rightMost), length))
26
27
// update the input digit minus the processed rightMost
28
tempNum /= 10
29
-
30
- // break the loop if all numbers are iterated
31
- if tempNum == 0 {
32
- break
33
- }
34
}
35
36
return number == sum
0 commit comments