Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
// because of how whitespace is (not) rendered.
65
]
}
},
"cSpell.words": ["reorderd"]
}
21 changes: 13 additions & 8 deletions exercises/concept/train-driver/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Instructions

Your friend Linus is a train driver who drives cargo trains between cities. Although they are amazing at handling trains, they are not amazing at handling logistics or computers. They would like to enlist your programming help organizing train details and correcting mistakes in route data.
Your friend Linus is a train driver who drives cargo trains between cities.
Although they are amazing at handling trains, they are not amazing at handling logistics or computers.
They would like to enlist your programming help organizing train details and correcting mistakes in route data.

```exercism/note
To practice, use the rest or spread operator to solve each of the tasks below.
```

## 1. Create a list of all wagons

Your friend has been keeping track of each wagon identifier (ID), but they are never sure how many wagons the system is going to have to process at any given time. It would be much easier for the rest of the logistics program to have this data packaged into a unified `array`.
Your friend has been keeping track of each wagon identifier (ID), but they are never sure how many wagons the system is going to have to process at any given time.
It would be much easier for the rest of the logistics program to have this data packaged into a unified `array`.

Implement a function `getListOfWagons` that accepts an arbitrary number of wagon IDs which are the IDs of each wagon.
Each ID will be a positive integer.
Expand All @@ -21,14 +24,16 @@ getListOfWagons(1, 7, 12, 3, 14, 8, 5);

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

At this point, you are starting to get a feel for the data and how it's used in the logistics program. The ID system always assigns the locomotive an ID of **1**, with the remainder of the wagons in the train assigned a randomly chosen ID greater than **1**.
At this point, you are starting to get a feel for the data and how it's used in the logistics program.
The ID system always assigns the locomotive an ID of **1**, with the remainder of the wagons in the train assigned a randomly chosen ID greater than **1**.

Your friend had to connect two new wagons to the train and forgot to update the system! Now, the first two wagons in the train `array` have to be moved to the end, or everything will be out of order.
Your friend had to connect two new wagons to the train and forgot to update the system!
Now, the first two wagons in the train `array` have to be moved to the end, or everything will be out of order.

Linus would be really grateful to you for fixing their mistakes.

Implement a function `fixListOfWagons` that accepts an array of the id of each wagon.
It `return` an `array` where the 2 first elements repositioned to the end of the `array` so that the locomotive can be in the front.
It `return`s an `array` where the 2 first elements repositioned to the end of the `array` so that the locomotive can be in the front.

```javascript
eachWagonsID = [2, 5, 1, 7, 4, 12, 6, 3, 13];
Expand All @@ -43,7 +48,7 @@ Uh-oh. some wagons seem to have gone missing.
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`.
All they can remember is that the missing values should be placed directly after the designated locomotive.

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

```javascript
Expand All @@ -59,7 +64,7 @@ Now that all the wagon data is correct, your friend would like you to update the
Initial routing information has been constructed as an `object`, and you friend would like you to update it with the additions provided.
Every route requires slightly different information, so your friend would really prefer a generic solution.

Implement a function extendRouteInformation that accepts two `objects`.
Implement a function `extendRouteInformation` that accepts two `objects`.
The first `object` contains which cities the train route moves between.

The second `object` contains other routing details such as train speed or length.
Expand All @@ -81,7 +86,7 @@ extendRouteInformation(route, moreRouteInformation);
Your friend has noticed that they don't need the arrival time in the routing information.
Therefore your friend would like you to separate the arrival time from the routing information.

Implement a function `separateArrivalTime` that accepts an object with the routing information.
Implement a function `separateTimeOfArrival` that accepts an object with the routing information.
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.

```javascript
Expand Down
37 changes: 18 additions & 19 deletions exercises/concept/train-driver/.meta/exemplar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,55 @@
// implementing this exercise.

/**
* Return each Wagons id in form of an array.
* Return each wagon's id in form of an array.
*
* @param {number[]} eachWagonsID
* @returns {number[]} each Wagons Wiegth
* @param {number[]} ids
* @returns {number[]} wagon ids
*/
export function getListOfWagons(...eachWagonsID) {
return eachWagonsID;
export function getListOfWagons(...ids) {
return ids;
}

/**
* Reorder the array of wagons by moving the first 2 wagons to the end of the array.
*
* @param {number[]} eachWagonsID
* @returns {number[]} reorderd list of wagons
* @param {number[]} ids
* @returns {number[]} reordered list of wagons
*/
export function fixListOfWagons(eachWagonsID) {
const [first, second, ...rest] = eachWagonsID;
export function fixListOfWagons([first, second, ...rest]) {
return [...rest, first, second];
}

/**
* Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID.
*
* @param {number[]} eachWagonsID
* @param {number[]} ids
* @param {number[]} missingWagons
* @returns {number[]} corrected list of wagons
*/
export function correctListOfWagons(eachWagonsID, missingWagons) {
const [first, ...rest] = eachWagonsID;
export function correctListOfWagons([first, ...rest], missingWagons) {
return [first, ...missingWagons, ...rest];
}

/**
* Extend route information by adding another object
*
* @param {Record<string, string>} route
* @param {Record<string, string>} moreRouteInformation
* @param {Record<string, string>} information
* @param {Record<string, string>} additional
* @returns {Record<string, string>} extended route information
*/
export function extendRouteInformation(route, moreRouteInformation) {
return { ...route, ...moreRouteInformation };
export function extendRouteInformation(information, additional) {
return { ...information, ...additional };
}

/**
* Separate arrival time from the route information object
*
* @param {Record<string, string>} route
* @param {Record<string, string>} information
* @returns {[string, Record<string, string>]} array with arrival time and object without arrival time
*/
export function separateTimeOfArrival(route) {
const { timeOfArrival, ...rest } = route;
export function separateTimeOfArrival(information) {
const { timeOfArrival, ...rest } = information;

return [timeOfArrival, rest];
}
26 changes: 13 additions & 13 deletions exercises/concept/train-driver/train-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,53 @@
// implementing this exercise.

/**
* Return each Wagons id in form of an array.
* Return each wagon's id in form of an array.
*
* @param {number[]} eachWagonsID
* @returns {number[]} each Wagons Wiegth
* @param {number[]} ids
* @returns {number[]} wagon ids
*/
export function getListOfWagons(eachWagonsID) {
export function getListOfWagons(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
throw new Error('Please implement the getListOfWagons function');
}

/**
* Reorder the array of wagons by moving the first 2 wagons to the end of the array.
*
* @param {number[]} eachWagonsID
* @param {number[]} ids
* @returns {number[]} reorderd list of wagons
*/
export function fixListOfWagons(eachWagonsID) {
export function fixListOfWagons(ids) {
throw new Error('Please implement the fixListOfWagons function');
}

/**
* Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID.
*
* @param {number[]} eachWagonsID
* @param {number[]} ids
* @param {number[]} missingWagons
* @returns {number[]} corrected list of wagons
*/
export function correctListOfWagons(eachWagonsID, missingWagons) {
export function correctListOfWagons(ids, missingWagons) {
throw new Error('Please implement the correctListOfWagons function');
}

/**
* Extend route information by adding another object
*
* @param {Record<string, string>} route
* @param {Record<string, string>} moreRouteInformation
* @param {Record<string, string>} information
* @param {Record<string, string>} additional
* @returns {Record<string, string>} extended route information
*/
export function extendRouteInformation(route, moreRouteInformation) {
export function extendRouteInformation(information, additional) {
throw new Error('Please implement the extendRouteInformation function');
}

/**
* Separate arrival time from the route information object
*
* @param {Record<string, string>} route
* @param {Record<string, string>} information
* @returns {[string, Record<string, string>]} array with arrival time and object without arrival time
*/
export function separateTimeOfArrival(route) {
export function separateTimeOfArrival(information) {
throw new Error('Please implement the separateTimeOfArrival function');
}
Loading