We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a8d52a0 commit 7f857e9Copy full SHA for 7f857e9
lib/dynamic/fizzbuzz.dart
@@ -1,11 +1,8 @@
1
String fizzbuzz(int n) {
2
- if (n % 3 == 0 && n % 5 == 0) {
3
- return 'FizzBuzz';
4
- } else if (n % 3 == 0) {
5
- return 'Fizz';
6
- } else if (n % 5 == 0) {
7
- return 'Buzz';
8
- } else {
9
- return '$n';
10
- }
+ return switch(n) {
+ int x when x % 3 == 0 && x % 5 == 0 => 'FizzBuzz',
+ int x when x % 3 == 0 => 'Fizz',
+ int x when x % 5 == 0 => 'Buzz',
+ _ => '$n'
+ };
11
}
test/dynamic/fizzbuzz_test.dart
@@ -4,8 +4,8 @@ import 'package:test/test.dart';
void main() {
//unit test
test('fizzbuzz()', () {
- final num = 20;
- final expectedValue = 'Buzz';
+ final num = 60;
+ final expectedValue = 'FizzBuzz';
print('-- FizzBuzz -- \n\n');
0 commit comments