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 scrabble-score: Create mentoring.md #2222

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from 1 commit
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
56 changes: 56 additions & 0 deletions tracks/dart/exercises/scrabble-score/mentoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Mentoring

## Reasonable solutions

This exercise can be solved in different ways. We will use two of them.
Show both of them to get them, to get them to know more dart concepts.
Map class will be used for both solutions.

### Solution 1: using fold method ***_recommended_***
```dart
int score([String word]) {
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
var values = {
'A': 1, 'B': 3, 'C': 3, 'D': 2,
'E': 1, 'F': 4, 'G': 2, 'H': 4,
'I': 1, 'J': 8, 'K': 5, 'L': 1,
'M': 3, 'N': 1, 'O': 1, 'P': 3,
'Q': 10, 'R': 1, 'S': 1, 'T': 1,
'U': 1, 'V': 4, 'W': 4, 'X': 8,
'Y': 4, 'Z': 10,
};

return word.toUpperCase().split("").fold(0, (prev, curr) => prev + values[curr]);
}
```

### Solution 2: using map and reduce methods
```dart
int score([String word]) {
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
var values = {
'A': 1, 'B': 3, 'C': 3, 'D': 2,
'E': 1, 'F': 4, 'G': 2, 'H': 4,
'I': 1, 'J': 8, 'K': 5, 'L': 1,
'M': 3, 'N': 1, 'O': 1, 'P': 3,
'Q': 10, 'R': 1, 'S': 1, 'T': 1,
'U': 1, 'V': 4, 'W': 4, 'X': 8,
'Y': 4, 'Z': 10,
};

return word.toUpperCase().split("").map((e) => values[e.toString()]).reduce((prev,curr) => prev + curr);
}
```

## Common suggestions
- Students need to know how [Map][reference-map-class] works, because they need it for both of the solutions
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
- Solution 1 is more important than Solution 2. They need the [fold-method][reference-fold-method] for future exercises

[reference-map-class]: https://api.dart.dev/stable/2.10.4/dart-core/Map-class.html
[reference-fold-method]: https://api.dart.dev/stable/1.10.1/dart-core/List/fold.html
[reference-map-method]: https://api.dart.dev/stable/2.9.1/dart-core/Iterable/map.html
[reference-reduce-method]: https://api.dart.dev/stable/2.14.4/dart-core/Iterable/reduce.html

## Solution Video

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

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