|
| 1 | +# Instructions |
| 2 | + |
| 3 | +Your friend is a train driver and has to drive cargo trains between cities. Although your friend isn't amazing with handling the computers and would like some help with it. Your friend would like your help organizing the train and correcting the mistakes in the data. |
| 4 | + |
| 5 | + |
| 6 | +```exercism/note |
| 7 | +To practice, use a for the rest or spread to solve each of the tasks below. |
| 8 | +``` |
| 9 | + |
| 10 | +## 1. Convert the data to an array |
| 11 | + |
| 12 | +Your friend has been keeping track of how much each wagon weighs. Although they are not sure how many wagons and would like the data to be returned as an array. |
| 13 | + |
| 14 | +```exercism/note |
| 15 | +
|
| 16 | +Implement a function `getListOfWagons` that accepts an unknown amount of whole numbers that contains the weight of each wagon. It should return an array of all the wagon weights. |
| 17 | +
|
| 18 | +``` |
| 19 | + |
| 20 | +```javascript |
| 21 | +getListOfWagons(5, 7, 12, 3, 14, 8, 3); |
| 22 | +// => [5, 7, 12, 3, 14, 8, 3] |
| 23 | +``` |
| 24 | + |
| 25 | +## 2. Move the first two elements to the end of the array |
| 26 | + |
| 27 | +Now that you got a general feel for handling your friend's data. Your friend has noticed that the first two days' values are not in the correct place. Your friend would like you to move the first two days' value to the end of the array. |
| 28 | + |
| 29 | +```exercism/note |
| 30 | +
|
| 31 | +Implement a function `fixListOfWagons` that accepts an array of the weight of each wagon. |
| 32 | +It returns an array where the 2 first elements are moved to the end of the array. |
| 33 | +
|
| 34 | +``` |
| 35 | + |
| 36 | +```javascript |
| 37 | +eachWagonsWieght = [2, 5, 0, 7, 4, 0, 1, 3, 1]; |
| 38 | +fixListOfWagons(eachWagonsWieght); |
| 39 | +// => [0, 7, 4, 0, 1, 3, 1, 2, 5] |
| 40 | +``` |
| 41 | + |
| 42 | +## 3. Add missing values |
| 43 | + |
| 44 | +Your friend realized that all data wasn't added and found another array which contains the missing values. |
| 45 | +Your friend would like you to add the missing values to the array. |
| 46 | +All they can remember is that the missing values should be placed after the first element in the array. |
| 47 | + |
| 48 | + |
| 49 | +```exercism/note |
| 50 | +
|
| 51 | +Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the values of the weight of each wagon as an argument. |
| 52 | +The second array should be added after the first element of the first array. |
| 53 | +
|
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | +```javascript |
| 58 | +eachWagonsWieght = [2, 5, 0, 7, 4, 1]; |
| 59 | +missingWagons = [3, 0, 6, 1]; |
| 60 | +CorrectListOfWagons(eachWagonsWieght, missingWagons); |
| 61 | +// => [2, 3, 0, 6, 1, 5, 0, 7, 4, 1] |
| 62 | +``` |
| 63 | + |
| 64 | +## 4. Update routing information |
| 65 | + |
| 66 | +Now that the wagon data is correct, your friend would like you to update the routing information. |
| 67 | +Your friend has an object with the routing information and would like you to add more routing information to the object. |
| 68 | +Every route requires a bit different information so your friend would prefer a generic solution. |
| 69 | + |
| 70 | + |
| 71 | +```exercism/note |
| 72 | +
|
| 73 | +Implement a function `updateRoutingInformation` that accepts two objects. |
| 74 | +The first object contains which city the train should go between and the second object contains more routing information. |
| 75 | +The function should return an object with the updated routing information. |
| 76 | +
|
| 77 | +``` |
| 78 | + |
| 79 | +```javascript |
| 80 | +route = {from: "Berlin", to: "Hamburg"}; |
| 81 | +moreRouteInformation = {length: 100, speed: 50}; |
| 82 | +updateRoutingInformation(route, moreRouteInformation); |
| 83 | +// => {from: "Berlin", to: "Hamburg", length: 100, speed: 50} |
| 84 | +``` |
| 85 | + |
| 86 | +## 5. Remove arrival time from routing information |
| 87 | + |
| 88 | +Your friend has noticed that they don't need the arrival time in the routing information. |
| 89 | +Therefore your friend would like you to remove the arrival time from the routing information. |
| 90 | + |
| 91 | +```exercism/note |
| 92 | +
|
| 93 | +Implement a function `removeArrivalTime` that accepts an object with the routing information. |
| 94 | +The function should return an object |
| 95 | +
|
| 96 | +``` |
| 97 | + |
| 98 | +```javascript |
| 99 | +routeInformation= { |
| 100 | + from: "Berlin", |
| 101 | + to: "Hamburg", |
| 102 | + length: 100, |
| 103 | + timeOfArrival: "10:10" |
| 104 | +}; |
| 105 | +removeTimeOfArrival(routeInformation); |
| 106 | +// => {from: "Berlin", to: "Hamburg", length: 100} |
| 107 | +``` |
0 commit comments