From b18db53c41e362d4a6c71b63bfa9e38767efec8d Mon Sep 17 00:00:00 2001 From: tom-clark-dev <116427463+tom-clark-dev@users.noreply.github.com> Date: Fri, 9 Dec 2022 08:58:03 +0000 Subject: [PATCH 1/3] Added Dart file for class-based solution --- .../Dart/dart_fibonacci_class.dart | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 fibonacci_series/Dart/dart_fibonacci_class.dart diff --git a/fibonacci_series/Dart/dart_fibonacci_class.dart b/fibonacci_series/Dart/dart_fibonacci_class.dart new file mode 100644 index 0000000..9d704ff --- /dev/null +++ b/fibonacci_series/Dart/dart_fibonacci_class.dart @@ -0,0 +1,27 @@ +import 'dart:io'; + +class Fibonacci { + static Iterable getSequence(int n) { + var sequence = []; + while (n >= 0) { + sequence.add(Fibonacci.getTerm(n)); + n--; + } + return sequence.reversed; + } + + static int getTerm(int n) { + if (n == 0) return 0; + if (n <= 2) return 1; + return Fibonacci.getTerm(n - 1) + Fibonacci.getTerm(n - 2); + } +} + +void main() { + print("Testing class Fibonacci..."); + + print(Fibonacci.getSequence(0).toString()); + print(Fibonacci.getSequence(1).toString()); + print(Fibonacci.getSequence(5).toString()); + print(Fibonacci.getSequence(12).toString()); +} From 83b1348720fa20741bb5c7d26d791d107f891807 Mon Sep 17 00:00:00 2001 From: tom-clark-dev <116427463+tom-clark-dev@users.noreply.github.com> Date: Fri, 9 Dec 2022 09:07:31 +0000 Subject: [PATCH 2/3] Updated method name --- fibonacci_series/Dart/dart_fibonacci_class.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fibonacci_series/Dart/dart_fibonacci_class.dart b/fibonacci_series/Dart/dart_fibonacci_class.dart index 9d704ff..4ab1b6f 100644 --- a/fibonacci_series/Dart/dart_fibonacci_class.dart +++ b/fibonacci_series/Dart/dart_fibonacci_class.dart @@ -1,7 +1,7 @@ import 'dart:io'; class Fibonacci { - static Iterable getSequence(int n) { + static Iterable getSeries(int n) { var sequence = []; while (n >= 0) { sequence.add(Fibonacci.getTerm(n)); @@ -20,8 +20,8 @@ class Fibonacci { void main() { print("Testing class Fibonacci..."); - print(Fibonacci.getSequence(0).toString()); - print(Fibonacci.getSequence(1).toString()); - print(Fibonacci.getSequence(5).toString()); - print(Fibonacci.getSequence(12).toString()); + print(Fibonacci.getSeries(0).toString()); + print(Fibonacci.getSeries(1).toString()); + print(Fibonacci.getSeries(5).toString()); + print(Fibonacci.getSeries(12).toString()); } From 37fd5e0b61dfc3591e3d783d95e388ace9e027bc Mon Sep 17 00:00:00 2001 From: tom-clark-dev <116427463+tom-clark-dev@users.noreply.github.com> Date: Fri, 9 Dec 2022 09:13:19 +0000 Subject: [PATCH 3/3] Updated variable name --- fibonacci_series/Dart/dart_fibonacci_class.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fibonacci_series/Dart/dart_fibonacci_class.dart b/fibonacci_series/Dart/dart_fibonacci_class.dart index 4ab1b6f..6dbf4eb 100644 --- a/fibonacci_series/Dart/dart_fibonacci_class.dart +++ b/fibonacci_series/Dart/dart_fibonacci_class.dart @@ -2,12 +2,12 @@ import 'dart:io'; class Fibonacci { static Iterable getSeries(int n) { - var sequence = []; + var series = []; while (n >= 0) { - sequence.add(Fibonacci.getTerm(n)); + series.add(Fibonacci.getTerm(n)); n--; } - return sequence.reversed; + return series.reversed; } static int getTerm(int n) {