REFACTOR: extract spare checking logic

This commit is contained in:
fiatcode 2026-02-10 11:55:31 +07:00
parent b6007c8115
commit 7c24567bfa

View file

@ -10,7 +10,7 @@ class BowlingGame {
int rollIndex = 0; int rollIndex = 0;
for (int frame = 0; frame < 10; frame++) { for (int frame = 0; frame < 10; frame++) {
if (_rolls[rollIndex] + _rolls[rollIndex + 1] == 10) { if (_isSpare(rollIndex)) {
totalScore += 10 + _rolls[rollIndex + 2]; totalScore += 10 + _rolls[rollIndex + 2];
rollIndex += 2; rollIndex += 2;
} else { } else {
@ -21,4 +21,8 @@ class BowlingGame {
return totalScore; return totalScore;
} }
bool _isSpare(int rollIndex) {
return _rolls[rollIndex] + _rolls[rollIndex + 1] == 10;
}
} }