Skip to content

Commit 166a823

Browse files
committed
Runned prettier and aded hints
1 parent d73f782 commit 166a823

File tree

8 files changed

+165
-123
lines changed

8 files changed

+165
-123
lines changed
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
# Hints
22

3-
## 1. Create a list of all wagons
3+
## General
4+
5+
- To extract multiple arguments in the function parameters so can you pack them with the `...<args>`.
6+
- To use rest and spread use the `...` operator.
47

8+
## 1. Create a list of all wagons
59

10+
- Multiple arguments in the function parameters can be packed with the `...<args>` operator.
611

712
## 2. Move the first two elements to the end of the array
813

9-
14+
- Using unpacking with the rest operator(`...`), lets you extract the first two elements of a `array` while keeping the rest intact.
15+
- To add another `array` into an existing `array`, you can use the `...` operator to "spread" the `array`.
1016

1117
## 3. Add missing values
1218

13-
19+
- Using unpacking with the rest operator(`...`), lets you extract the first two elements of a `array` while keeping the rest intact.
20+
- To add another `array` into an existing `array`, you can use the `...` operator to "spread" the `array`.
1421

1522
## 4. Extend routing information
1623

17-
24+
- To add another `object` into an existing `object`, you can use the `...` operator to "spread" the `object`.
1825

1926
## 5. Separate arrival time from routing information
2027

21-
28+
- To extract a value from an `object` while keeping the rest intact, you can use the rest operator(`...`).

exercises/concept/train-driver/.docs/instructions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Uh-oh. some wagons seem to have gone missing.
4343
Fortunately, your friend just found another `array` which appears to contain the missing wagon IDs, and would like you to add them into the main wagon ID `array`.
4444
All they can remember is that the missing values should be placed directly after the designated locomotive.
4545

46-
Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the IDs of each wagon as the arguments.
46+
Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the IDs of each wagon as the arguments.
4747
The wagon IDs of the second `array` should be added into the first `array` directly after the locomotive (ID 1).
4848

4949
```javascript
@@ -70,8 +70,8 @@ The variable `moreRouteInformation` can contain different properties.
7070
```
7171

7272
```javascript
73-
route = {from: "Berlin", to: "Hamburg"};
74-
moreRouteInformation = {length: "100", speed: "50"};
73+
route = { from: "Berlin", to: "Hamburg" };
74+
moreRouteInformation = { length: "100", speed: "50" };
7575
extendRouteInformation(route, moreRouteInformation);
7676
// => {from: "Berlin", to: "Hamburg", length: "100", speed: "50"}
7777
```
@@ -85,11 +85,11 @@ Implement a function `separateArrivalTime` that accepts an object with the routi
8585
The function should return an array there the first element of the array is the arrival time and the second element is an object with the routing information without arrival time.
8686

8787
```javascript
88-
routeInformation= {
88+
routeInformation = {
8989
from: "Berlin",
9090
to: "Hamburg",
9191
length: "100",
92-
timeOfArrival: "10:10"
92+
timeOfArrival: "10:10",
9393
};
9494
separateTimeOfArrival(routeInformation);
9595
// => ["10:10", {from: "Berlin", to: "Hamburg", length: "100"}]

exercises/concept/train-driver/.docs/introduction.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Similarly to arrays, the rest operator can also be used to collect one or more o
3030

3131
```javascript
3232
const { street, ...address } = {
33-
street: 'Platz der Republik 1',
34-
postalCode: '11011',
35-
city: 'Berlin',
33+
street: "Platz der Republik 1",
34+
postalCode: "11011",
35+
city: "Berlin",
3636
};
3737
street;
3838
// => 'Platz der Republik 1'
@@ -46,11 +46,11 @@ When `...` appears in a function definition next to its last argument, that para
4646

4747
```javascript
4848
function concat(...strings) {
49-
return strings.join(' ');
49+
return strings.join(" ");
5050
}
51-
concat('one');
51+
concat("one");
5252
// => 'one'
53-
concat('one', 'two', 'three');
53+
concat("one", "two", "three");
5454
// => 'one two three'
5555
```
5656

@@ -65,7 +65,7 @@ const oneToFive = [1, 2, 3, 4, 5];
6565
const oneToTen = [...oneToFive, 6, 7, 8, 9, 10];
6666
oneToTen;
6767
// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
68-
const woow = ['A', ...oneToFive, 'B', 'C', 'D', 'E', ...oneToFive, 42];
68+
const woow = ["A", ...oneToFive, "B", "C", "D", "E", ...oneToFive, 42];
6969
woow;
7070
// => ["A", 1, 2, 3, 4, 5, "B", "C", "D", "E", 1, 2, 3, 4, 5, 42]
7171
```
@@ -76,13 +76,13 @@ Similarly to arrays, the spread operator can also be used to copy properties fro
7676

7777
```javascript
7878
let address = {
79-
postalCode: '11011',
80-
city: 'Berlin',
79+
postalCode: "11011",
80+
city: "Berlin",
8181
};
82-
address = { ...address, country: 'Germany' };
82+
address = { ...address, country: "Germany" };
8383
// => {
8484
// postalCode: '11011',
8585
// city: 'Berlin',
8686
// country: 'Germany',
8787
// }
88-
```
88+
```

exercises/concept/train-driver/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"authors": [
3-
"meatball"
3+
"meatball133"
44
],
55
"contributors": [
66
"bethanyg",

exercises/concept/train-driver/.meta/design.md

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,23 @@
22

33
## Learning objectives
44

5-
- What does a for loop do
6-
- Syntax `for(...){...}`
7-
- What are the different parts of the for loop header
8-
- How to iterate over an array with a for loop
9-
- What is the increment/decrement operator `i++`/`i--`
5+
- Using spread to turn an array into a list of parameters
6+
- Using rest elements to turn a list of parameters into an array
7+
- Using spread to turn an extract value out of an object
8+
- Using spread to combine objects
9+
- Using rest to collect multiple parameters into an array
1010

11-
## Out of Scope
11+
## Out of scope
1212

13-
The following topics are out of scope because they are covered by another concept exercise.
14-
15-
- Other loops like `while`
16-
- Other possibilities of iterating over an array
17-
- `break` and `continue` are only mentioned in the about.md file here because they will be more in focus in the `while` exercise
13+
- Default values
1814

1915
## Concepts
2016

21-
The Concepts this exercise unlocks are:
22-
23-
- `for-loops`
24-
- `increment-decrement`
17+
- `rest-and-spread`
2518

2619
## Prerequisites
2720

28-
- `arrays` because they are used to iterate over them in the exercise
29-
- `comparison` for writing the condition in the loop header
30-
- `conditionals` because they introduced the student to the concept of conditional execution
31-
32-
## Analyzer
33-
34-
This exercise could benefit from the following rules in the [analyzer][analyzer]:
35-
36-
For all tasks check that the student actually used a for loop.
37-
38-
1. `totalBirdCount`
39-
40-
- Verify that the condition is written with `< x.length` instead of `<= y.length -1`.
41-
- Check whether a shorthand assignment `+=` was used to increase the sum (non-essential feedback).
42-
- Verify the total was properly initialized with `0` instead of e.g. `null`
43-
- Verify the increment operator was used in loop header step
44-
45-
2. `birdsInWeek`
46-
47-
- Verify a helper variable was used instead of duplicating the calculation in the initialization and condition of the loop
48-
- Other checks should be the same as for `totalBirdCount`
49-
50-
3. `fixBirdCountLog`
51-
52-
- Check whether a shorthand assignment `+=` was used to increase the loop counter (non-essential feedback)
53-
- Check whether the increment operator was used in the loop body
54-
55-
## Notes
56-
57-
The exercise is inspired by [Bird Watcher Exercise in the C# track][csharp-bird-watcher] but the original exercise included more concepts and subsequently also tasks that cover all of these concepts.
58-
Since the exercise for the JavaScript track should be focussed on the for loop, the tasks where reduced and changed accordingly.
59-
60-
[analyzer]: https://github.com/exercism/javascript-analyzer
61-
[csharp-bird-watcher]: https://github.com/exercism/csharp/blob/main/exercises/concept/bird-watcher/.docs/instructions.md
21+
- `arrays` are needed to understand array restructuring
22+
- `functions` are needed as basis for rest parameters
23+
- `objects` are needed for object spread etc.
24+
- `array-destructuring` are needed to understand rest elements

exercises/concept/train-driver/.meta/exemplar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* @param {number[]} eachWagonsID
1111
* @returns {number[]} each Wagons Wiegth
1212
*/
13-
export function getListOfWagons(...eachWagonsID) {
14-
return eachWagonsID
13+
export function getListOfWagons(...eachWagonsID) {
14+
return eachWagonsID;
1515
}
1616

1717
/**
@@ -57,4 +57,4 @@ export function extendRouteInformation(route, moreRouteInformation) {
5757
export function separateTimeOfArrival(route) {
5858
const { timeOfArrival, ...rest } = route;
5959
return [timeOfArrival, rest];
60-
}
60+
}

exercises/concept/train-driver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@exercism/javascript-train-driver",
33
"description": "Exercism concept exercise on rest and spread operators",
4-
"author": "Meatball",
4+
"author": "Meatball133",
55
"private": true,
66
"license": "MIT",
77
"repository": {

0 commit comments

Comments
 (0)