dart-exercism/beer-song/lib/beer_song.dart
2024-10-14 11:37:17 +02:00

24 lines
979 B
Dart

class BeerSong {
List<String> recite(int amountOfBeers, int amountOfVerses) {
if (amountOfVerses == 0) return [];
if (amountOfBeers == 0)
return [
'No more bottles of beer on the wall, no more bottles of beer.',
'Go to the store and buy some more, 99 bottles of beer on the wall.',
];
if (amountOfBeers == 1)
return [
'1 bottle of beer on the wall, 1 bottle of beer.',
'Take it down and pass it around, no more bottles of beer on the wall.',
if (amountOfVerses > 1) '',
] +
recite(amountOfBeers - 1, amountOfVerses - 1);
return [
'$amountOfBeers bottles of beer on the wall, $amountOfBeers bottles of beer.',
'Take one down and pass it around, ${(amountOfBeers - 1 == 1) ? '1 bottle' : '${amountOfBeers - 1} bottles'} of beer on the wall.',
if (amountOfVerses > 1) ''
] +
recite(amountOfBeers - 1, amountOfVerses - 1);
}
}