Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dart/difference-of-squares] Create mentoring.md #2225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tracks/dart/exercises/difference-of-squares/mentoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Mentoring

## Reasonable solutions

We need to have two three methods:

- the first one is sqareOfSum that will return the sum of all numbers and squared afterwards
- the second method is the sumOfSquares which returns the sum of sqared numbers
- the last method - differenceOfSquares - returns the difference of both of the methods above

This exercise allows students to be tidy in coding their solution. Putting everything in methods that can be used in other methods is welcomed practice.

```dart
class DifferenceOfSquares {
int squareOfSum(int n) => pow(List<int>.generate(n, (i) => i + 1).reduce((a,b) => a+b), 2);
int sumOfSquares(int n) => List<int>.generate(n, (i) => pow(i+1, 2)).reduce((a,b) => a+b);
int differenceOfSquares(int n) => squareOfSum(n) - sumOfSquares(n);
}
```


## Common suggestions

- they need to create three methods
- use [generate-method][reference-generate-method] to generate a List of incremented numbers
- [reduce-method][reference-reduce-method] sums the generated list
- [pow-method][reference-pow-method] is a maths function to put x to the power of y

[reference-generate-method]: https://fluttermaster.com/how-to-use-list-generate-in-dart/
[reference-reduce-method]: https://api.dart.dev/stable/2.18.1/dart-core/Iterable/reduce.html
[reference-pow-method]: https://api.dart.dev/stable/2.10.5/dart-math/pow.html


## Solution Video

Step by step [video][youtube-video] guide solution for this exercise

[youtube-video]: https://www.youtube.com/watch?v=iwvcEKG_2qU