From 7c24567bfa4f543f3a4f15f3024b65f73ec388f7 Mon Sep 17 00:00:00 2001 From: fiatcode Date: Tue, 10 Feb 2026 11:55:31 +0700 Subject: [PATCH] REFACTOR: extract spare checking logic --- lib/bowling_game.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bowling_game.dart b/lib/bowling_game.dart index e58e92b..2cc3615 100644 --- a/lib/bowling_game.dart +++ b/lib/bowling_game.dart @@ -10,7 +10,7 @@ class BowlingGame { int rollIndex = 0; for (int frame = 0; frame < 10; frame++) { - if (_rolls[rollIndex] + _rolls[rollIndex + 1] == 10) { + if (_isSpare(rollIndex)) { totalScore += 10 + _rolls[rollIndex + 2]; rollIndex += 2; } else { @@ -21,4 +21,8 @@ class BowlingGame { return totalScore; } + + bool _isSpare(int rollIndex) { + return _rolls[rollIndex] + _rolls[rollIndex + 1] == 10; + } }