Skip to content

Commit 5a293e3

Browse files
committed
Update loop in isarmstrong
1 parent a9a11e1 commit 5a293e3

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

math/armstrong/isarmstrong.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@ func IsArmstrong(number int) bool {
1919
// to get the number of digits in the number
2020
length := float64(len(strconv.Itoa(number)))
2121

22-
// get the right most digit
23-
for {
22+
// get the right most digit and break the loop once all digits are iterated
23+
for tempNum > 0 {
2424
rightMost = tempNum % 10
2525
sum += int(math.Pow(float64(rightMost), length))
2626

2727
// update the input digit minus the processed rightMost
2828
tempNum /= 10
29-
30-
// break the loop if all numbers are iterated
31-
if tempNum == 0 {
32-
break
33-
}
3429
}
3530

3631
return number == sum

0 commit comments

Comments
 (0)