From f98dbb898ba2f100057f84dad69d92abb1952784 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Fri, 11 Nov 2022 19:12:19 +0100 Subject: [PATCH 01/23] Added filles --- exercises/concept/train-driver/.docs/hints.md | 25 ++++ .../train-driver/.docs/instructions.md | 107 ++++++++++++++++++ .../train-driver/.docs/introduction.md | 88 ++++++++++++++ exercises/concept/train-driver/.eslintrc | 14 +++ exercises/concept/train-driver/.gitignore | 3 + .../concept/train-driver/.meta/config.json | 23 ++++ .../concept/train-driver/.meta/design.md | 61 ++++++++++ .../concept/train-driver/.meta/exemplar.js | 60 ++++++++++ exercises/concept/train-driver/.npmrc | 1 + exercises/concept/train-driver/LICENSE | 21 ++++ .../concept/train-driver/babel.config.js | 4 + exercises/concept/train-driver/package.json | 29 +++++ .../concept/train-driver/train-driver.js | 57 ++++++++++ .../concept/train-driver/train-driver.spec.js | 103 +++++++++++++++++ 14 files changed, 596 insertions(+) create mode 100644 exercises/concept/train-driver/.docs/hints.md create mode 100644 exercises/concept/train-driver/.docs/instructions.md create mode 100644 exercises/concept/train-driver/.docs/introduction.md create mode 100644 exercises/concept/train-driver/.eslintrc create mode 100644 exercises/concept/train-driver/.gitignore create mode 100644 exercises/concept/train-driver/.meta/config.json create mode 100644 exercises/concept/train-driver/.meta/design.md create mode 100644 exercises/concept/train-driver/.meta/exemplar.js create mode 100644 exercises/concept/train-driver/.npmrc create mode 100644 exercises/concept/train-driver/LICENSE create mode 100644 exercises/concept/train-driver/babel.config.js create mode 100644 exercises/concept/train-driver/package.json create mode 100644 exercises/concept/train-driver/train-driver.js create mode 100644 exercises/concept/train-driver/train-driver.spec.js diff --git a/exercises/concept/train-driver/.docs/hints.md b/exercises/concept/train-driver/.docs/hints.md new file mode 100644 index 0000000000..d980b399b7 --- /dev/null +++ b/exercises/concept/train-driver/.docs/hints.md @@ -0,0 +1,25 @@ +# Hints + +## 1. Determine the total number of birds that you counted so far + +- Refer to the exercise introduction for an example of how to use a for loop to iterate over an array. +- Use a helper variable to store the total count and increase that variable as you go through the array. +- Think about the correct initial value for that helper variable. +- Refer back to the [array concept][concept-arrays] to recap how to retrieve values from an array. + +## 2. Calculate the number of visiting birds in a specific week + +- This task is similar to the first one. + You can copy your code as a starting point. +- Think about which indexes in the array you would need to take into account for week number 1 and 2, respectively. +- Now, find a general way to calculate the first and the last index that should be considered. +- With that, you can set up the for loop to only iterate over the relevant section of the array. + +## 3. Fix a counting mistake + +- Again, you need to set up a for loop to iterate over the whole bird count array. +- This time you only need to visit every second entry in the array. +- Change the step so the counter variable is increased accordingly after each iteration. +- In the body of the for loop you can use the increment operator to change the value of an element in an array in place. + +[concept-arrays]: /tracks/javascript/concepts/arrays diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md new file mode 100644 index 0000000000..c6186d8264 --- /dev/null +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -0,0 +1,107 @@ +# Instructions + +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. + + +```exercism/note +To practice, use a for the rest or spread to solve each of the tasks below. +``` + +## 1. Convert the data to an array + +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. + +```exercism/note + +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. + +``` + +```javascript +getListOfWagons(5, 7, 12, 3, 14, 8, 3); +// => [5, 7, 12, 3, 14, 8, 3] +``` + +## 2. Move the first two elements to the end of the array + +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. + +```exercism/note + +Implement a function `fixListOfWagons` that accepts an array of the weight of each wagon. +It returns an array where the 2 first elements are moved to the end of the array. + +``` + +```javascript +eachWagonsWieght = [2, 5, 0, 7, 4, 0, 1, 3, 1]; +fixListOfWagons(eachWagonsWieght); +// => [0, 7, 4, 0, 1, 3, 1, 2, 5] +``` + +## 3. Add missing values + +Your friend realized that all data wasn't added and found another array which contains the missing values. +Your friend would like you to add the missing values to the array. +All they can remember is that the missing values should be placed after the first element in the array. + + +```exercism/note + +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. +The second array should be added after the first element of the first array. + +``` + + +```javascript +eachWagonsWieght = [2, 5, 0, 7, 4, 1]; +missingWagons = [3, 0, 6, 1]; +CorrectListOfWagons(eachWagonsWieght, missingWagons); +// => [2, 3, 0, 6, 1, 5, 0, 7, 4, 1] +``` + +## 4. Update routing information + +Now that the wagon data is correct, your friend would like you to update the routing information. +Your friend has an object with the routing information and would like you to add more routing information to the object. +Every route requires a bit different information so your friend would prefer a generic solution. + + +```exercism/note + +Implement a function `updateRoutingInformation` that accepts two objects. +The first object contains which city the train should go between and the second object contains more routing information. +The function should return an object with the updated routing information. + +``` + +```javascript +route = {from: "Berlin", to: "Hamburg"}; +moreRouteInformation = {length: 100, speed: 50}; +updateRoutingInformation(route, moreRouteInformation); +// => {from: "Berlin", to: "Hamburg", length: 100, speed: 50} +``` + +## 5. Remove arrival time from routing information + +Your friend has noticed that they don't need the arrival time in the routing information. +Therefore your friend would like you to remove the arrival time from the routing information. + +```exercism/note + +Implement a function `removeArrivalTime` that accepts an object with the routing information. +The function should return an object + +``` + +```javascript +routeInformation= { + from: "Berlin", + to: "Hamburg", + length: 100, + timeOfArrival: "10:10" +}; +removeTimeOfArrival(routeInformation); +// => {from: "Berlin", to: "Hamburg", length: 100} +``` diff --git a/exercises/concept/train-driver/.docs/introduction.md b/exercises/concept/train-driver/.docs/introduction.md new file mode 100644 index 0000000000..545afa161f --- /dev/null +++ b/exercises/concept/train-driver/.docs/introduction.md @@ -0,0 +1,88 @@ +# Introduction + +JavaScript has a built-in `...` operator that makes it easier to work with indefinite numbers of elements. Depending on the context, it's called either a _rest operator_ or _spread operator_. + +## Rest operator + +### Rest elements + +When `...` appears on the left-hand side of an assignment, those three dots are known as the `rest` operator. The three dots together with a variable name is called a rest element. It collects zero or more values, and stores them into a single array. + +```javascript +const [a, b, ...everythingElse] = [0, 1, 1, 2, 3, 5, 8]; +a; +// => 0 +b; +// => 1 +everythingElse; +// => [1, 2, 3, 5, 8] +``` + +Note that in JavaScript, unlike some other languages, a `rest` element cannot have a trailing comma. It _must_ be the last element in a destructuring assignment. The example below throws a `SyntaxError`: + +```javascript +const [...items, last] = [2, 4, 8, 16] +``` + +### Rest properties + +Similarly to arrays, the rest operator can also be used to collect one or more object properties and store them in a single object. + +```javascript +const { street, ...address } = { + street: 'Platz der Republik 1', + postalCode: '11011', + city: 'Berlin', +}; +street; +// => 'Platz der Republik 1' +address; +// => {postalCode: '11011', city: 'Berlin'} +``` + +## Rest parameters + +When `...` appears in a function definition next to its last argument, that parameter is called a _rest parameter_. It allows the function to accept an indefinite number of arguments as an array. + +```javascript +function concat(...strings) { + return strings.join(' '); +} +concat('one'); +// => 'one' +concat('one', 'two', 'three'); +// => 'one two three' +``` + +## Spread + +### Spread elements + +When `...` appears on the right-hand side of an assignment, it's known as the `spread` operator. It expands an array into a list of elements. Unlike the rest element, it can appear anywhere in an array literal expression, and there can be more than one. + +```javascript +const oneToFive = [1, 2, 3, 4, 5]; +const oneToTen = [...oneToFive, 6, 7, 8, 9, 10]; +oneToTen; +// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +const woow = ['A', ...oneToFive, 'B', 'C', 'D', 'E', ...oneToFive, 42]; +woow; +// => ["A", 1, 2, 3, 4, 5, "B", "C", "D", "E", 1, 2, 3, 4, 5, 42] +``` + +### Spread properties + +Similarly to arrays, the spread operator can also be used to copy properties from one object to another. + +```javascript +let address = { + postalCode: '11011', + city: 'Berlin', +}; +address = { ...address, country: 'Germany' }; +// => { +// postalCode: '11011', +// city: 'Berlin', +// country: 'Germany', +// } +``` \ No newline at end of file diff --git a/exercises/concept/train-driver/.eslintrc b/exercises/concept/train-driver/.eslintrc new file mode 100644 index 0000000000..1d4446029c --- /dev/null +++ b/exercises/concept/train-driver/.eslintrc @@ -0,0 +1,14 @@ +{ + "root": true, + "extends": "@exercism/eslint-config-javascript", + "env": { + "jest": true + }, + "overrides": [ + { + "files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"], + "excludedFiles": ["custom.spec.js"], + "extends": "@exercism/eslint-config-javascript/maintainers" + } + ] +} diff --git a/exercises/concept/train-driver/.gitignore b/exercises/concept/train-driver/.gitignore new file mode 100644 index 0000000000..bdb912f98a --- /dev/null +++ b/exercises/concept/train-driver/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn-error.log + diff --git a/exercises/concept/train-driver/.meta/config.json b/exercises/concept/train-driver/.meta/config.json new file mode 100644 index 0000000000..e283cf9f9c --- /dev/null +++ b/exercises/concept/train-driver/.meta/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "meatball" + ], + "files": { + "solution": [ + "train-driver.js" + ], + "test": [ + "train-driver.spec.js" + ], + "exemplar": [ + ".meta/exemplar.js" + ] + }, + "blurb": "Professionalize using rest and spread operators.", + "custom": { + "version.tests.compatibility": "jest-27", + "flag.tests.task-per-describe": true, + "flag.tests.may-run-long": false, + "flag.tests.includes-optional": false + } +} diff --git a/exercises/concept/train-driver/.meta/design.md b/exercises/concept/train-driver/.meta/design.md new file mode 100644 index 0000000000..554e26f2c7 --- /dev/null +++ b/exercises/concept/train-driver/.meta/design.md @@ -0,0 +1,61 @@ +# Design + +## Learning objectives + +- What does a for loop do +- Syntax `for(...){...}` +- What are the different parts of the for loop header +- How to iterate over an array with a for loop +- What is the increment/decrement operator `i++`/`i--` + +## Out of Scope + +The following topics are out of scope because they are covered by another concept exercise. + +- Other loops like `while` +- Other possibilities of iterating over an array +- `break` and `continue` are only mentioned in the about.md file here because they will be more in focus in the `while` exercise + +## Concepts + +The Concepts this exercise unlocks are: + +- `for-loops` +- `increment-decrement` + +## Prerequisites + +- `arrays` because they are used to iterate over them in the exercise +- `comparison` for writing the condition in the loop header +- `conditionals` because they introduced the student to the concept of conditional execution + +## Analyzer + +This exercise could benefit from the following rules in the [analyzer][analyzer]: + +For all tasks check that the student actually used a for loop. + +1. `totalBirdCount` + + - Verify that the condition is written with `< x.length` instead of `<= y.length -1`. + - Check whether a shorthand assignment `+=` was used to increase the sum (non-essential feedback). + - Verify the total was properly initialized with `0` instead of e.g. `null` + - Verify the increment operator was used in loop header step + +2. `birdsInWeek` + + - Verify a helper variable was used instead of duplicating the calculation in the initialization and condition of the loop + - Other checks should be the same as for `totalBirdCount` + +3. `fixBirdCountLog` + + - Check whether a shorthand assignment `+=` was used to increase the loop counter (non-essential feedback) + - Check whether the increment operator was used in the loop body + +## Notes + +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. +Since the exercise for the JavaScript track should be focussed on the for loop, the tasks where reduced and changed accordingly. + +[analyzer]: https://github.com/exercism/javascript-analyzer +[csharp-bird-watcher]: https://github.com/exercism/csharp/blob/main/exercises/concept/bird-watcher/.docs/instructions.md diff --git a/exercises/concept/train-driver/.meta/exemplar.js b/exercises/concept/train-driver/.meta/exemplar.js new file mode 100644 index 0000000000..77673ba585 --- /dev/null +++ b/exercises/concept/train-driver/.meta/exemplar.js @@ -0,0 +1,60 @@ +// @ts-check +// +// The line above enables type checking for this file. Various IDEs interpret +// the @ts-check directive. It will give you helpful autocompletion when +// implementing this exercise. + +/** + * Return each Wagons Wiegth. + * + * @param {number[]} eachWagonsWiegth + * @returns {number[]} each Wagons Wiegth + */ + export function getListOfWagons(...eachWagonsWiegth) { + return eachWagonsWiegth; +} + +/** + * Reorder the array of wagons by moving the first 2 wagons to the end of the array. + * + * @param {number[]} eachWagonsWieght + * @returns {number[]} reorderd list of wagons + */ +export function fixListOfWagons(eachWagonsWieght) { + const [first, second, ...rest] = eachWagonsWieght; + return [...rest, first, second]; +} + +/** + * Fixes the list of wagons by inserting an array of wagons after the first element in eachWagonsWieght. + * + * @param {number[]} eachWagonsWieght + * @param {number[]} missingWagons + * @returns {number[]} corrected list of wagons + */ +export function correctListOfWagons(eachWagonsWieght, missingWagons) { + const [first, ...rest] = eachWagonsWieght; + return [first, ...missingWagons, ...rest]; +} + +/** + * Updates the route information by adding more routing information + * + * @param {Record} route + * @param {Record} moreRouteInformation + * @returns {Record} updates route information + */ +export function updateRoutingInformation(route, moreRouteInformation) { + return { ...route, ...moreRouteInformation }; +} + +/** + * Remove arrival time from the route information object + * + * @param {Record} route + * @returns {Record} object without arrival time + */ +export function removeTimeOfArrival(route) { + const { arrivalTime, ...rest } = route; + return rest; +} \ No newline at end of file diff --git a/exercises/concept/train-driver/.npmrc b/exercises/concept/train-driver/.npmrc new file mode 100644 index 0000000000..d26df800bb --- /dev/null +++ b/exercises/concept/train-driver/.npmrc @@ -0,0 +1 @@ +audit=false diff --git a/exercises/concept/train-driver/LICENSE b/exercises/concept/train-driver/LICENSE new file mode 100644 index 0000000000..90e73be03b --- /dev/null +++ b/exercises/concept/train-driver/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Exercism + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/exercises/concept/train-driver/babel.config.js b/exercises/concept/train-driver/babel.config.js new file mode 100644 index 0000000000..b781d5a667 --- /dev/null +++ b/exercises/concept/train-driver/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: ['@exercism/babel-preset-javascript'], + plugins: [], +}; diff --git a/exercises/concept/train-driver/package.json b/exercises/concept/train-driver/package.json new file mode 100644 index 0000000000..f6b7f194f6 --- /dev/null +++ b/exercises/concept/train-driver/package.json @@ -0,0 +1,29 @@ +{ + "name": "@exercism/javascript-train-driver", + "description": "Exercism concept exercise on rest and spread operators", + "author": "Meatball", + "private": true, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/exercism/javascript", + "directory": "exercises/concept/train-driver" + }, + "devDependencies": { + "@babel/core": "^7.19.6", + "@exercism/babel-preset-javascript": "^0.2.1", + "@exercism/eslint-config-javascript": "^0.6.0", + "@types/jest": "^29.2.0", + "@types/node": "^18.11.0", + "babel-jest": "^29.2.2", + "core-js": "~3.26.0", + "eslint": "^8.26.0", + "jest": "^29.2.1" + }, + "dependencies": {}, + "scripts": { + "test": "jest ./*", + "watch": "jest --watch ./*", + "lint": "eslint ." + } +} diff --git a/exercises/concept/train-driver/train-driver.js b/exercises/concept/train-driver/train-driver.js new file mode 100644 index 0000000000..588d7e5d00 --- /dev/null +++ b/exercises/concept/train-driver/train-driver.js @@ -0,0 +1,57 @@ +// @ts-check +// +// The line above enables type checking for this file. Various IDEs interpret +// the @ts-check directive. It will give you helpful autocompletion when +// implementing this exercise. + +/** + * Return each Wagons Wiegth. + * + * @param {number[]} eachWagonsWiegth + * @returns {number[]} each Wagons Wiegth + */ +export function getListOfWagons(eachWagonsWiegth) { + 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[]} eachWagonsWieght + * @returns {number[]} reorderd list of wagons + */ +export function fixListOfWagons(eachWagonsWieght) { + throw new Error('Please implement the fixListOfWagons function'); +} + +/** + * Fixes the list of wagons by inserting an array of wagons after the first element in eachWagonsWieght. + * + * @param {number[]} eachWagonsWieght + * @param {number[]} missingWagons + * @returns {number[]} corrected list of wagons + */ +export function correctListOfWagons(eachWagonsWieght, missingWagons) { + throw new Error('Please implement the correctListOfWagons function'); +} + +/** + * Updates the route information by adding more routing information + * + * @param {Record} route + * @param {Record} moreRouteInformation + * @returns {Record} updates route information + */ +export function updateRoutingInformation(route, moreRouteInformation) { + throw new Error('Please implement the updateRoutingInformation function'); +} + +/** + * Remove arrival time from the route information object + * + * @param {Record} route + * @returns {Record} object without arrival time + */ +export function removeTimeOfArrival(route) { + throw new Error('Please implement the removeTimeOfArrival function'); +} \ No newline at end of file diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js new file mode 100644 index 0000000000..37fc305a41 --- /dev/null +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -0,0 +1,103 @@ +import { getListOfWagons, fixListOfWagons, correctListOfWagons, updateRoutingInformation, removeTimeOfArrival } from './train-driver'; + +describe('getListOfWagons', () => { + test('return the correct array', () => { + expect(getListOfWagons(4,5,2,7,4)).toEqual([4,5,2,7,4]); + }); + + test('works for a few arrgument', () => { + expect(getListOfWagons(4,5)).toEqual([4,5]); + }); + + test('works for a one arrgument', () => { + expect(getListOfWagons(5)).toEqual([5]); + }); + + test('works for many argument', () => { + expect(getListOfWagons(4,5,6,3,6,8,4,1,4,7)).toEqual([4,5,6,3,6,8,4,1,4,7]); + }); +}); + +describe('fixListOfWagons', () => { + test('reorder the first 2 wagons to the end of the array', () => { + const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0]; + const expected = [5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0, 3, 0]; + expect(fixListOfWagons(eachWagonsWieght)).toEqual(expected); + }); + + test('works when only 2 wagons given', () => { + const eachWagonsWieght = [1, 2]; + expect(fixListOfWagons(eachWagonsWieght)).toEqual([1, 2]); + }); + + test('works for a few wagons', () => { + const eachWagonsWieght = [3, 4, 3, 3, 2, 1, 0]; + expect(fixListOfWagons(eachWagonsWieght)).toEqual([3, 3, 2, 1, 0, 3, 4]); + }); +}); + +describe('correctListOfWagons', () => { + test('returns a wagon wieght list with the inserted array of values', () => { + const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; + const missingWagons = [8, 0, 5, 8, 0, 8, 0]; + const expected = [3, 8, 0, 5, 8, 0, 8, 0, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; + expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + }); + + test('works for short arrays', () => { + const eachWagonsWieght = [2, 0, 1, 0]; + const missingWagons = [8, 6, 0]; + const expected = [2, 8, 6, 0, 0, 1, 0]; + expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + }); + + test('works when missingWagons is longer', () => { + const eachWagonsWieght = [2, 0, 1, 0]; + const missingWagons = [8, 6, 0, 5, 8, 0, 8, 0]; + const expected = [2, 8, 6, 0, 5, 8, 0, 8, 0, 0, 1, 0]; + expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + }); +}); + +describe('updateRoutingInformation', () => { + test('correctly updates route information', () => { + const route = {from: "Berlin", to: "Hamburg"}; + const moreRouteInformation = {timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; + const expected = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; + expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + }); + + test('works when not adding precipitation', () => { + const route = {from: "Paris", to: "London"}; + const moreRouteInformation = {timeOfArrival: "10:30", temperature: "20"}; + const expected = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; + expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + }); + + test('works when written in diffrent order', () => { + const route = {from: "Gothenburg", to: "Copenhagen"}; + const moreRouteInformation = {precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; + const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; + expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + }); +}); + +describe('removeTimeOfArrival', () => { + test('remove removeTimeOfArrival from object', () => { + const route = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; + const expected = {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}; + expect(removeTimeOfArrival(route)).toEqual(expected); + }); + + test('remove removeTimeOfArrival with shorter object', () => { + const route = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; + const expected = {from: "Paris", to: "London", temperature: "20"}; + expect(removeTimeOfArrival(route)).toEqual(expected); + }); + + test('remove removeTimeOfArrival from object', () => { + const route = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; + const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}; + expect(removeTimeOfArrival(route)).toEqual(expected); + }); +}); From 77ca83d2f863ac12e6f969f5ca85121a18681243 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Fri, 11 Nov 2022 20:16:12 +0100 Subject: [PATCH 02/23] fixes --- exercises/concept/train-driver/.docs/instructions.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index c6186d8264..26f4ee25fc 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -1,6 +1,8 @@ # Instructions -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. +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. ```exercism/note @@ -13,7 +15,8 @@ Your friend has been keeping track of how much each wagon weighs. Although they ```exercism/note -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. +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. ``` @@ -24,7 +27,8 @@ getListOfWagons(5, 7, 12, 3, 14, 8, 3); ## 2. Move the first two elements to the end of the array -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. +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. ```exercism/note From 92ecfbaa97799f6a7eb91f1ebc8f8c6d82fd4458 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 09:48:24 +0100 Subject: [PATCH 03/23] fixes --- .../train-driver/.docs/instructions.md | 70 +++++++------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 26f4ee25fc..baff875614 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -2,88 +2,76 @@ 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. +Your friend would like your help organizing the train and correcting mistakes in the data. ```exercism/note -To practice, use a for the rest or spread to solve each of the tasks below. +To practice, use the rest or spread operator to solve each of the tasks below. ``` -## 1. Convert the data to an array +## 1. Create a list of all wagons -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. +Your friend has been keeping track of eachs wagon identifer. Although they are not sure how many wagons and would like the data to be returned as an array. -```exercism/note - -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. - -``` +Implement a function `getListOfWagons` that accepts an unknown amount of possitve whole numbers that contains the id of each wagon. +It should return an array of all the wagon ids. ```javascript -getListOfWagons(5, 7, 12, 3, 14, 8, 3); -// => [5, 7, 12, 3, 14, 8, 3] +getListOfWagons(1, 7, 12, 3, 14, 8, 5); +// => [1, 7, 12, 3, 14, 8, 3] ``` ## 2. Move the first two elements to the end of the array -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. - -```exercism/note +Now that you got a general feel for handling your friend's data. +The train id system works by the locomotive having id one and the rest of the wagons geting a random id. +You friend had to connect two new wagons to the train and forgot to update the id system. +Now the first two wagons in the array has to be moved to the back of the train. +Your friend would like you to move the first two wagons to the end of the array. -Implement a function `fixListOfWagons` that accepts an array of the weight of each wagon. +Implement a function `fixListOfWagons` that accepts an array of the id of each wagon. It returns an array where the 2 first elements are moved to the end of the array. -``` - ```javascript -eachWagonsWieght = [2, 5, 0, 7, 4, 0, 1, 3, 1]; +eachWagonsWieght = [2, 5, 1, 7, 4, 12, 6, 3, 13]; fixListOfWagons(eachWagonsWieght); -// => [0, 7, 4, 0, 1, 3, 1, 2, 5] +// => [1, 7, 4, 12, 6, 3, 13, 2, 5] ``` ## 3. Add missing values -Your friend realized that all data wasn't added and found another array which contains the missing values. +Your friend realized that all data wasn't added and found another array which contains the missing wagons. Your friend would like you to add the missing values to the array. -All they can remember is that the missing values should be placed after the first element in the array. - - -```exercism/note +All they can remember is that the missing values should be placed after the locomotive in the array. -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. +Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the id of of each wagon as an argument. The second array should be added after the first element of the first array. -``` - - ```javascript -eachWagonsWieght = [2, 5, 0, 7, 4, 1]; -missingWagons = [3, 0, 6, 1]; +eachWagonsWieght = [1, 5, 20, 7, 4, 8]; +missingWagons = [3, 17, 6, 15]; CorrectListOfWagons(eachWagonsWieght, missingWagons); -// => [2, 3, 0, 6, 1, 5, 0, 7, 4, 1] +// => [1, 3, 17, 6, 15, 5, 20, 7, 4, 8] ``` -## 4. Update routing information +## 4. Extend routing information Now that the wagon data is correct, your friend would like you to update the routing information. Your friend has an object with the routing information and would like you to add more routing information to the object. Every route requires a bit different information so your friend would prefer a generic solution. - -```exercism/note - -Implement a function `updateRoutingInformation` that accepts two objects. +Implement a function `extendRouteInformation` that accepts two objects. The first object contains which city the train should go between and the second object contains more routing information. The function should return an object with the updated routing information. +```exercism/note +The variable `moreRouteInformation` can contain diffrent properties. ``` ```javascript route = {from: "Berlin", to: "Hamburg"}; moreRouteInformation = {length: 100, speed: 50}; -updateRoutingInformation(route, moreRouteInformation); +extendRouteInformation(route, moreRouteInformation); // => {from: "Berlin", to: "Hamburg", length: 100, speed: 50} ``` @@ -92,13 +80,9 @@ updateRoutingInformation(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 remove the arrival time from the routing information. -```exercism/note - Implement a function `removeArrivalTime` that accepts an object with the routing information. The function should return an object -``` - ```javascript routeInformation= { from: "Berlin", From d25d85e36444ba60ace3751b8f97a2dbd948e33b Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 11:08:31 +0100 Subject: [PATCH 04/23] further fixes and updated last exercise --- .../train-driver/.docs/instructions.md | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index baff875614..7013853e7a 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -4,16 +4,15 @@ 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 mistakes in the 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 eachs wagon identifer. Although they are not sure how many wagons and would like the data to be returned as an array. +Your friend has been keeping track of each wagon identifier. Although they are not sure how many wagons and would like the data to be returned as an array. -Implement a function `getListOfWagons` that accepts an unknown amount of possitve whole numbers that contains the id of each wagon. +Implement a function `getListOfWagons` that accepts an unknown amount of positive whole numbers that contains the id of each wagon. It should return an array of all the wagon ids. ```javascript @@ -24,9 +23,9 @@ getListOfWagons(1, 7, 12, 3, 14, 8, 5); ## 2. Move the first two elements to the end of the array Now that you got a general feel for handling your friend's data. -The train id system works by the locomotive having id one and the rest of the wagons geting a random id. -You friend had to connect two new wagons to the train and forgot to update the id system. -Now the first two wagons in the array has to be moved to the back of the train. +The train id system works by the locomotive having id number one and the rest of the wagons having a random id. +Your friend had to connect two new wagons to the train and forgot to update the id system. +Now the first two wagons in the array have to be moved to the back of the train. Your friend would like you to move the first two wagons to the end of the array. Implement a function `fixListOfWagons` that accepts an array of the id of each wagon. @@ -44,7 +43,7 @@ Your friend realized that all data wasn't added and found another array which co Your friend would like you to add the missing values to the array. All they can remember is that the missing values should be placed after the locomotive in the array. -Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the id of of each wagon as an argument. +Given this new information, write a function called `CorrectListOfWagons` that takes two arrays which have the id of each wagon as an argument. The second array should be added after the first element of the first array. ```javascript @@ -65,31 +64,31 @@ The first object contains which city the train should go between and the second The function should return an object with the updated routing information. ```exercism/note -The variable `moreRouteInformation` can contain diffrent properties. +The variable `moreRouteInformation` can contain different properties. ``` ```javascript route = {from: "Berlin", to: "Hamburg"}; -moreRouteInformation = {length: 100, speed: 50}; +moreRouteInformation = {length: "100", speed: "50"}; extendRouteInformation(route, moreRouteInformation); -// => {from: "Berlin", to: "Hamburg", length: 100, speed: 50} +// => {from: "Berlin", to: "Hamburg", length: "100", speed: "50"} ``` -## 5. Remove arrival time from routing information +## 5. Separate arrival time from routing information Your friend has noticed that they don't need the arrival time in the routing information. -Therefore your friend would like you to remove the arrival time from the routing information. +Therefore your friend would like you to separate the arrival time from the routing information. -Implement a function `removeArrivalTime` that accepts an object with the routing information. -The function should return an object +Implement a function `separateArrivalTime` that accepts an object with the routing information. +The function should return two objects. ```javascript routeInformation= { from: "Berlin", to: "Hamburg", - length: 100, + length: "100", timeOfArrival: "10:10" }; -removeTimeOfArrival(routeInformation); -// => {from: "Berlin", to: "Hamburg", length: 100} +separateTimeOfArrival(routeInformation); +// => {timeOfArrival: "10:10"}, {from: "Berlin", to: "Hamburg", length: "100"} ``` From fb96f63cac034d7600eccfcf357e0800bbf74eeb Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 11:14:12 +0100 Subject: [PATCH 05/23] Replace whole numbers --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 7013853e7a..b469f80b91 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -12,7 +12,7 @@ To practice, use the rest or spread operator to solve each of the tasks below. Your friend has been keeping track of each wagon identifier. Although they are not sure how many wagons and would like the data to be returned as an array. -Implement a function `getListOfWagons` that accepts an unknown amount of positive whole numbers that contains the id of each wagon. +Implement a function `getListOfWagons` that accepts an unknown amount of positive integer that contains the id of each wagon. It should return an array of all the wagon ids. ```javascript From 439ddd200377a6bd11ce4b3a3143e1a1a6f6c781 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 11:15:00 +0100 Subject: [PATCH 06/23] Update instructions.md --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index b469f80b91..bf9d06bb89 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -12,7 +12,7 @@ To practice, use the rest or spread operator to solve each of the tasks below. Your friend has been keeping track of each wagon identifier. Although they are not sure how many wagons and would like the data to be returned as an array. -Implement a function `getListOfWagons` that accepts an unknown amount of positive integer that contains the id of each wagon. +Implement a function `getListOfWagons` that accepts an unknown amount of positive integers that contains the id of each wagon. It should return an array of all the wagon ids. ```javascript From 8e6b360b5cc2c946706d1b1b90532e6cc132bd00 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 14:18:18 +0100 Subject: [PATCH 07/23] Various fixes and updated test file --- exercises/concept/train-driver/.docs/hints.md | 30 +++---- .../train-driver/.docs/instructions.md | 4 +- .../concept/train-driver/.meta/exemplar.js | 38 ++++----- .../concept/train-driver/train-driver.js | 32 ++++---- .../concept/train-driver/train-driver.spec.js | 80 +++++++++---------- 5 files changed, 90 insertions(+), 94 deletions(-) diff --git a/exercises/concept/train-driver/.docs/hints.md b/exercises/concept/train-driver/.docs/hints.md index d980b399b7..deb481bb05 100644 --- a/exercises/concept/train-driver/.docs/hints.md +++ b/exercises/concept/train-driver/.docs/hints.md @@ -1,25 +1,21 @@ # Hints -## 1. Determine the total number of birds that you counted so far +## 1. Create a list of all wagons -- Refer to the exercise introduction for an example of how to use a for loop to iterate over an array. -- Use a helper variable to store the total count and increase that variable as you go through the array. -- Think about the correct initial value for that helper variable. -- Refer back to the [array concept][concept-arrays] to recap how to retrieve values from an array. -## 2. Calculate the number of visiting birds in a specific week -- This task is similar to the first one. - You can copy your code as a starting point. -- Think about which indexes in the array you would need to take into account for week number 1 and 2, respectively. -- Now, find a general way to calculate the first and the last index that should be considered. -- With that, you can set up the for loop to only iterate over the relevant section of the array. +## 2. Move the first two elements to the end of the array -## 3. Fix a counting mistake -- Again, you need to set up a for loop to iterate over the whole bird count array. -- This time you only need to visit every second entry in the array. -- Change the step so the counter variable is increased accordingly after each iteration. -- In the body of the for loop you can use the increment operator to change the value of an element in an array in place. -[concept-arrays]: /tracks/javascript/concepts/arrays +## 3. Add missing values + + + +## 4. Extend routing information + + + +## 5. Separate arrival time from routing information + + diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index bf9d06bb89..cae3f778c9 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -80,7 +80,7 @@ Your friend has noticed that they don't need the arrival time in the routing inf 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. -The function should return two objects. +The function should return an array there the first elment of the arrival time and the second element is an object with the routing information. ```javascript routeInformation= { @@ -90,5 +90,5 @@ routeInformation= { timeOfArrival: "10:10" }; separateTimeOfArrival(routeInformation); -// => {timeOfArrival: "10:10"}, {from: "Berlin", to: "Hamburg", length: "100"} +// => ["10:10", {from: "Berlin", to: "Hamburg", length: "100"}] ``` diff --git a/exercises/concept/train-driver/.meta/exemplar.js b/exercises/concept/train-driver/.meta/exemplar.js index 77673ba585..311f34709c 100644 --- a/exercises/concept/train-driver/.meta/exemplar.js +++ b/exercises/concept/train-driver/.meta/exemplar.js @@ -5,56 +5,56 @@ // implementing this exercise. /** - * Return each Wagons Wiegth. + * Return each Wagons id in form of an array. * - * @param {number[]} eachWagonsWiegth + * @param {number[]} eachWagonsID * @returns {number[]} each Wagons Wiegth */ - export function getListOfWagons(...eachWagonsWiegth) { - return eachWagonsWiegth; + export function getListOfWagons(...eachWagonsID) { + return eachWagonsID } /** * Reorder the array of wagons by moving the first 2 wagons to the end of the array. * - * @param {number[]} eachWagonsWieght + * @param {number[]} eachWagonsID * @returns {number[]} reorderd list of wagons */ -export function fixListOfWagons(eachWagonsWieght) { - const [first, second, ...rest] = eachWagonsWieght; +export function fixListOfWagons(eachWagonsID) { + const [first, second, ...rest] = eachWagonsID; return [...rest, first, second]; } /** - * Fixes the list of wagons by inserting an array of wagons after the first element in eachWagonsWieght. + * Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID. * - * @param {number[]} eachWagonsWieght + * @param {number[]} eachWagonsID * @param {number[]} missingWagons * @returns {number[]} corrected list of wagons */ -export function correctListOfWagons(eachWagonsWieght, missingWagons) { - const [first, ...rest] = eachWagonsWieght; +export function correctListOfWagons(eachWagonsID, missingWagons) { + const [first, ...rest] = eachWagonsID; return [first, ...missingWagons, ...rest]; } /** - * Updates the route information by adding more routing information + * Extend route information by adding another object * * @param {Record} route * @param {Record} moreRouteInformation - * @returns {Record} updates route information + * @returns {Record} extended route information */ -export function updateRoutingInformation(route, moreRouteInformation) { +export function extendRouteInformation(route, moreRouteInformation) { return { ...route, ...moreRouteInformation }; } /** - * Remove arrival time from the route information object + * Separate arrival time from the route information object * * @param {Record} route - * @returns {Record} object without arrival time + * @returns {[string, Record]} array with arrival time and object without arrival time */ -export function removeTimeOfArrival(route) { - const { arrivalTime, ...rest } = route; - return rest; +export function separateTimeOfArrival(route) { + const { timeOfArrival, ...rest } = route; + return [timeOfArrival, rest]; } \ No newline at end of file diff --git a/exercises/concept/train-driver/train-driver.js b/exercises/concept/train-driver/train-driver.js index 588d7e5d00..da40852ced 100644 --- a/exercises/concept/train-driver/train-driver.js +++ b/exercises/concept/train-driver/train-driver.js @@ -5,53 +5,53 @@ // implementing this exercise. /** - * Return each Wagons Wiegth. + * Return each Wagons id in form of an array. * - * @param {number[]} eachWagonsWiegth + * @param {number[]} eachWagonsID * @returns {number[]} each Wagons Wiegth */ -export function getListOfWagons(eachWagonsWiegth) { +export function getListOfWagons(eachWagonsID) { 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[]} eachWagonsWieght + * @param {number[]} eachWagonsID * @returns {number[]} reorderd list of wagons */ -export function fixListOfWagons(eachWagonsWieght) { +export function fixListOfWagons(eachWagonsID) { throw new Error('Please implement the fixListOfWagons function'); } /** - * Fixes the list of wagons by inserting an array of wagons after the first element in eachWagonsWieght. + * Fixes the array of wagons by inserting an array of wagons after the first element in eachWagonsID. * - * @param {number[]} eachWagonsWieght + * @param {number[]} eachWagonsID * @param {number[]} missingWagons * @returns {number[]} corrected list of wagons */ -export function correctListOfWagons(eachWagonsWieght, missingWagons) { +export function correctListOfWagons(eachWagonsID, missingWagons) { throw new Error('Please implement the correctListOfWagons function'); } /** - * Updates the route information by adding more routing information + * Extend route information by adding another object * * @param {Record} route * @param {Record} moreRouteInformation - * @returns {Record} updates route information + * @returns {Record} extended route information */ -export function updateRoutingInformation(route, moreRouteInformation) { - throw new Error('Please implement the updateRoutingInformation function'); +export function extendRouteInformation(route, moreRouteInformation) { + throw new Error('Please implement the extendRouteInformation function'); } /** - * Remove arrival time from the route information object + * Separate arrival time from the route information object * * @param {Record} route - * @returns {Record} object without arrival time + * @returns {[string, Record]} array with arrival time and object without arrival time */ -export function removeTimeOfArrival(route) { - throw new Error('Please implement the removeTimeOfArrival function'); +export function separateTimeOfArrival(route) { + throw new Error('Please implement the separateTimeOfArrival function'); } \ No newline at end of file diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js index 37fc305a41..4ad8f5736c 100644 --- a/exercises/concept/train-driver/train-driver.spec.js +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -1,103 +1,103 @@ -import { getListOfWagons, fixListOfWagons, correctListOfWagons, updateRoutingInformation, removeTimeOfArrival } from './train-driver'; +import { getListOfWagons, fixListOfWagons, correctListOfWagons, extendRouteInformation, separateTimeOfArrival } from './train-driver'; describe('getListOfWagons', () => { test('return the correct array', () => { - expect(getListOfWagons(4,5,2,7,4)).toEqual([4,5,2,7,4]); + expect(getListOfWagons(1,5,2,7,4)).toEqual([1,5,2,7,4]); }); test('works for a few arrgument', () => { - expect(getListOfWagons(4,5)).toEqual([4,5]); + expect(getListOfWagons(1,5)).toEqual([1,5]); }); test('works for a one arrgument', () => { - expect(getListOfWagons(5)).toEqual([5]); + expect(getListOfWagons(1)).toEqual([1]); }); test('works for many argument', () => { - expect(getListOfWagons(4,5,6,3,6,8,4,1,4,7)).toEqual([4,5,6,3,6,8,4,1,4,7]); + expect(getListOfWagons(1,5,6,3,9,8,4,14,24,7)).toEqual([1,5,6,3,9,8,4,14,24,7]); }); }); describe('fixListOfWagons', () => { test('reorder the first 2 wagons to the end of the array', () => { - const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0]; - const expected = [5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0, 3, 0]; - expect(fixListOfWagons(eachWagonsWieght)).toEqual(expected); + const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19]; + const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7]; + expect(fixListOfWagons(eachWagonsID)).toEqual(expected); }); - test('works when only 2 wagons given', () => { - const eachWagonsWieght = [1, 2]; - expect(fixListOfWagons(eachWagonsWieght)).toEqual([1, 2]); + test('works when only 3 wagons given', () => { + const eachWagonsID = [4, 2, 1]; + expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]); }); test('works for a few wagons', () => { - const eachWagonsWieght = [3, 4, 3, 3, 2, 1, 0]; - expect(fixListOfWagons(eachWagonsWieght)).toEqual([3, 3, 2, 1, 0, 3, 4]); + const eachWagonsID = [3, 4, 1, 5, 7, 9, 10]; + expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]); }); }); describe('correctListOfWagons', () => { test('returns a wagon wieght list with the inserted array of values', () => { - const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; - const missingWagons = [8, 0, 5, 8, 0, 8, 0]; - const expected = [3, 8, 0, 5, 8, 0, 8, 0, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; + const missingWagons = [8, 10, 5, 9, 3, 7, 20]; + const expected = [1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); test('works for short arrays', () => { - const eachWagonsWieght = [2, 0, 1, 0]; - const missingWagons = [8, 6, 0]; - const expected = [2, 8, 6, 0, 0, 1, 0]; - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + const eachWagonsID = [1, 7, 15, 24]; + const missingWagons = [8, 6, 4]; + const expected = [1, 8, 6, 4, 7, 15, 24]; + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); test('works when missingWagons is longer', () => { - const eachWagonsWieght = [2, 0, 1, 0]; - const missingWagons = [8, 6, 0, 5, 8, 0, 8, 0]; - const expected = [2, 8, 6, 0, 5, 8, 0, 8, 0, 0, 1, 0]; - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); + const eachWagonsID = [1, 7, 15, 24]; + const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13]; + const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24]; + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); }); -describe('updateRoutingInformation', () => { - test('correctly updates route information', () => { +describe('extendRouteInformation', () => { + test('correctly extend route information', () => { const route = {from: "Berlin", to: "Hamburg"}; const moreRouteInformation = {timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; const expected = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); }); test('works when not adding precipitation', () => { const route = {from: "Paris", to: "London"}; const moreRouteInformation = {timeOfArrival: "10:30", temperature: "20"}; const expected = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); }); test('works when written in diffrent order', () => { const route = {from: "Gothenburg", to: "Copenhagen"}; const moreRouteInformation = {precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); }); }); -describe('removeTimeOfArrival', () => { - test('remove removeTimeOfArrival from object', () => { +describe('separateTimeOfArrival', () => { + test('seperate timeOfArrival from object', () => { const route = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; - const expected = {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}; - expect(removeTimeOfArrival(route)).toEqual(expected); + const expected = ["12:00", {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}] + expect(separateTimeOfArrival(route)).toEqual(expected); }); - test('remove removeTimeOfArrival with shorter object', () => { + test('seperate timeOfArrival with shorter object', () => { const route = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; - const expected = {from: "Paris", to: "London", temperature: "20"}; - expect(removeTimeOfArrival(route)).toEqual(expected); + const expected = ["10:30", {from: "Paris", to: "London", temperature: "20"}] + expect(separateTimeOfArrival(route)).toEqual(expected); }); - test('remove removeTimeOfArrival from object', () => { + test('seperate timeOfArrival from object', () => { const route = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; - const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}; - expect(removeTimeOfArrival(route)).toEqual(expected); + const expected = ["21:20", {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}] + expect(separateTimeOfArrival(route)).toEqual(expected); }); }); From 1a0a3fcf65fe0dfdedb03e8d7a6f3599d0df2bc3 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 14:20:36 +0100 Subject: [PATCH 08/23] fix smal typo --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index cae3f778c9..20f101d300 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -80,7 +80,7 @@ Your friend has noticed that they don't need the arrival time in the routing inf 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. -The function should return an array there the first elment of the arrival time and the second element is an object with the routing information. +The function should return an array there the first elment of they array is the arrival time and the second element is an object with the routing information without arrivaltime. ```javascript routeInformation= { From 71a9dac1ed49195b2b66b66b35dc9f901528f9f8 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 12 Nov 2022 14:23:30 +0100 Subject: [PATCH 09/23] fix small typo --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 20f101d300..ef8dcee2ba 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -80,7 +80,7 @@ Your friend has noticed that they don't need the arrival time in the routing inf 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. -The function should return an array there the first elment of they array is the arrival time and the second element is an object with the routing information without arrivaltime. +The function should return an array there the first elment of the array is the arrival time and the second element is an object with the routing information without arrivaltime. ```javascript routeInformation= { From a327c00a7ee9e31791f0e580e4f8db74518f741c Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Tue, 15 Nov 2022 20:21:09 +0100 Subject: [PATCH 10/23] Small typo fix --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index ef8dcee2ba..2725d25b44 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -80,7 +80,7 @@ Your friend has noticed that they don't need the arrival time in the routing inf 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. -The function should return an array there the first elment of the array is the arrival time and the second element is an object with the routing information without arrivaltime. +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 routeInformation= { From e1af39ef70e162a81e4d443e354b1ee617567353 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 12:05:55 +0100 Subject: [PATCH 11/23] Updated the story and added contributors --- .../train-driver/.docs/instructions.md | 48 ++++++++++--------- .../concept/train-driver/.meta/config.json | 4 ++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 2725d25b44..42fdd6f138 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -1,8 +1,7 @@ # Instructions -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 mistakes in the data. +Your friend is a Locomotive Engineer who drives cargo trains between cities. +Although your friend is great handling the trains, they aren't amazing handling the logistics computers and would like your programming help organizing the train and correcting mistakes in the data. ```exercism/note To practice, use the rest or spread operator to solve each of the tasks below. @@ -10,10 +9,9 @@ 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. Although they are not sure how many wagons and would like the data to be returned as an array. +Your friend has been keeping track of each wagon identifier, but they're never sure how many wagons they are going to have to process at any given time. It would be much easier for the rest of the logistics program to have the data to be returned as an array. -Implement a function `getListOfWagons` that accepts an unknown amount of positive integers that contains the id of each wagon. -It should return an array of all the wagon ids. +Implement a function `getListOfWagons` that accepts an unknown amount of positive integers which are the IDs of each wagon. ```javascript getListOfWagons(1, 7, 12, 3, 14, 8, 5); @@ -22,14 +20,15 @@ getListOfWagons(1, 7, 12, 3, 14, 8, 5); ## 2. Move the first two elements to the end of the array -Now that you got a general feel for handling your friend's data. -The train id system works by the locomotive having id number one and the rest of the wagons having a random id. -Your friend had to connect two new wagons to the train and forgot to update the id system. -Now the first two wagons in the array have to be moved to the back of the train. -Your friend would like you to move the first two wagons to the end of the array. +At this point, you are starting to get a feel for your friend's data and how it's used in the logistics program. +The train ID system works by assigning the locomotive an ID of `1` and then assigning the remainder of the wagons a randomly chosen ID greater than `1`. + +But then your friend had to connect two new wagons to the train and forgot to update the system! +Now the first two wagons in the `array` have to be moved to the back of the train, or everything will be out of order. +Your friend would be really grateful to you for fixing their mistake. Implement a function `fixListOfWagons` that accepts an array of the id of each wagon. -It returns an array where the 2 first elements are moved to the end of the array. +It `return` an `array` where the 2 first elements repositioned to the end of the `array`. ```javascript eachWagonsWieght = [2, 5, 1, 7, 4, 12, 6, 3, 13]; @@ -39,12 +38,13 @@ fixListOfWagons(eachWagonsWieght); ## 3. Add missing values -Your friend realized that all data wasn't added and found another array which contains the missing wagons. -Your friend would like you to add the missing values to the array. -All they can remember is that the missing values should be placed after the locomotive in the array. +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 id of each wagon as an argument. -The second array should be added after the first element of the first array. +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 eachWagonsWieght = [1, 5, 20, 7, 4, 8]; @@ -55,13 +55,15 @@ CorrectListOfWagons(eachWagonsWieght, missingWagons); ## 4. Extend routing information -Now that the wagon data is correct, your friend would like you to update the routing information. -Your friend has an object with the routing information and would like you to add more routing information to the object. -Every route requires a bit different information so your friend would prefer a generic solution. +Now that all the wagon data is correct, your friend would like you to update the systems routing information. +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`. +The first `object` contains which cities the train route moves between. -Implement a function `extendRouteInformation` that accepts two objects. -The first object contains which city the train should go between and the second object contains more routing information. -The function should return an object with the updated routing information. +The second `object` contains other routing details such as train speed or length. +The function should return a consolidated `object` with all routing information. ```exercism/note The variable `moreRouteInformation` can contain different properties. diff --git a/exercises/concept/train-driver/.meta/config.json b/exercises/concept/train-driver/.meta/config.json index e283cf9f9c..fd1c5906d3 100644 --- a/exercises/concept/train-driver/.meta/config.json +++ b/exercises/concept/train-driver/.meta/config.json @@ -2,6 +2,10 @@ "authors": [ "meatball" ], + "contributors": [ + "bethanyg", + "junedev" + ], "files": { "solution": [ "train-driver.js" From d5ae91d388519df6473c93e9c90780eab5597fa3 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 15:12:09 +0100 Subject: [PATCH 12/23] fix typo --- exercises/concept/train-driver/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 42fdd6f138..77251c6d86 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -49,7 +49,7 @@ The wagon IDs of the second `array` should be added into the first `array` direc ```javascript eachWagonsWieght = [1, 5, 20, 7, 4, 8]; missingWagons = [3, 17, 6, 15]; -CorrectListOfWagons(eachWagonsWieght, missingWagons); +correctListOfWagons(eachWagonsWieght, missingWagons); // => [1, 3, 17, 6, 15, 5, 20, 7, 4, 8] ``` From 6d38528e9253a494e86b967b881fca2e56fc7ffa Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:12:53 +0100 Subject: [PATCH 13/23] fix --- exercises/concept/train-driver/.docs/instructions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 77251c6d86..7151d4519c 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -31,8 +31,8 @@ Implement a function `fixListOfWagons` that accepts an array of the id of each w It `return` an `array` where the 2 first elements repositioned to the end of the `array`. ```javascript -eachWagonsWieght = [2, 5, 1, 7, 4, 12, 6, 3, 13]; -fixListOfWagons(eachWagonsWieght); +eachWagonsId = [2, 5, 1, 7, 4, 12, 6, 3, 13]; +fixListOfWagons(eachWagonsId); // => [1, 7, 4, 12, 6, 3, 13, 2, 5] ``` @@ -49,7 +49,7 @@ The wagon IDs of the second `array` should be added into the first `array` direc ```javascript eachWagonsWieght = [1, 5, 20, 7, 4, 8]; missingWagons = [3, 17, 6, 15]; -correctListOfWagons(eachWagonsWieght, missingWagons); +correctListOfWagons(eachWagonsId, missingWagons); // => [1, 3, 17, 6, 15, 5, 20, 7, 4, 8] ``` From 94163e1ae751c7f0de5bba293ed139d077cdb56f Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:15:19 +0100 Subject: [PATCH 14/23] Update instructions.md --- exercises/concept/train-driver/.docs/instructions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 7151d4519c..41ccbaad19 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -31,8 +31,8 @@ Implement a function `fixListOfWagons` that accepts an array of the id of each w It `return` an `array` where the 2 first elements repositioned to the end of the `array`. ```javascript -eachWagonsId = [2, 5, 1, 7, 4, 12, 6, 3, 13]; -fixListOfWagons(eachWagonsId); +eachWagonsID = [2, 5, 1, 7, 4, 12, 6, 3, 13]; +fixListOfWagons(eachWagonsID); // => [1, 7, 4, 12, 6, 3, 13, 2, 5] ``` @@ -47,9 +47,9 @@ Given this new information, write a function called `CorrectListOfWagons` that t The wagon IDs of the second `array` should be added into the first `array` directly after the locomotive (ID 1). ```javascript -eachWagonsWieght = [1, 5, 20, 7, 4, 8]; +eachWagonsID = [1, 5, 20, 7, 4, 8]; missingWagons = [3, 17, 6, 15]; -correctListOfWagons(eachWagonsId, missingWagons); +correctListOfWagons(eachWagonsID, missingWagons); // => [1, 3, 17, 6, 15, 5, 20, 7, 4, 8] ``` From 4e1b62336ebbd33186c44e03fa0b65172cf722fe Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:27:22 +0100 Subject: [PATCH 15/23] Further fixes --- exercises/concept/train-driver/.docs/instructions.md | 2 +- exercises/concept/train-driver/.meta/exemplar.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 41ccbaad19..6f8725e8db 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -28,7 +28,7 @@ Now the first two wagons in the `array` have to be moved to the back of the trai Your friend would be really grateful to you for fixing their mistake. 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`. +It `return` an `array` where the 2 first elements repositioned to the end of the `array` and the locomotive is added to the front. ```javascript eachWagonsID = [2, 5, 1, 7, 4, 12, 6, 3, 13]; diff --git a/exercises/concept/train-driver/.meta/exemplar.js b/exercises/concept/train-driver/.meta/exemplar.js index 311f34709c..92ddd76dca 100644 --- a/exercises/concept/train-driver/.meta/exemplar.js +++ b/exercises/concept/train-driver/.meta/exemplar.js @@ -22,7 +22,7 @@ */ export function fixListOfWagons(eachWagonsID) { const [first, second, ...rest] = eachWagonsID; - return [...rest, first, second]; + return [1, ...rest, first, second]; } /** From b86a9942e5a58ab02169eca51c72d25d000b9fef Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:39:52 +0100 Subject: [PATCH 16/23] fix bug created --- exercises/concept/train-driver/.meta/exemplar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/train-driver/.meta/exemplar.js b/exercises/concept/train-driver/.meta/exemplar.js index 92ddd76dca..311f34709c 100644 --- a/exercises/concept/train-driver/.meta/exemplar.js +++ b/exercises/concept/train-driver/.meta/exemplar.js @@ -22,7 +22,7 @@ */ export function fixListOfWagons(eachWagonsID) { const [first, second, ...rest] = eachWagonsID; - return [1, ...rest, first, second]; + return [...rest, first, second]; } /** From d73f782edc6edc44f06d238e4fb57b7278579051 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Thu, 29 Dec 2022 12:38:53 +0100 Subject: [PATCH 17/23] Fixes and changes to instructions --- config.json | 10 +++++++++- .../train-driver/.docs/instructions.md | 20 +++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/config.json b/config.json index a6ecfdd7b7..88c4270d79 100644 --- a/config.json +++ b/config.json @@ -116,10 +116,18 @@ "slug": "elyses-destructured-enchantments", "name": "Elyses Destructured Enchantments", "uuid": "d9b5cd13-2f2b-4034-a571-e66c847ed6f8", - "concepts": ["array-destructuring", "rest-and-spread"], + "concepts": ["array-destructuring"], "prerequisites": ["arrays", "functions", "objects"], "status": "beta" }, + { + "slug": "train-driver", + "name": "Train Driver", + "uuid": "6cef6712-cf1d-4b3e-9ace-1de3450b4285", + "concepts": ["rest-and-spread"], + "prerequisites": ["array-destructuring"], + "status": "beta" + }, { "slug": "elyses-looping-enchantments", "name": "Elyses Looping Enchantments", diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 6f8725e8db..13f25507c9 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -1,7 +1,6 @@ # Instructions -Your friend is a Locomotive Engineer who drives cargo trains between cities. -Although your friend is great handling the trains, they aren't amazing handling the logistics computers and would like your programming help organizing the train and correcting mistakes in the 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. @@ -9,9 +8,11 @@ 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, but they're never sure how many wagons they are going to have to process at any given time. It would be much easier for the rest of the logistics program to have the data to be returned as an 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 unknown amount of positive integers which are the IDs of each wagon. +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. +The function should then return the given IDs as a single `array`. ```javascript getListOfWagons(1, 7, 12, 3, 14, 8, 5); @@ -20,15 +21,14 @@ 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 your friend's data and how it's used in the logistics program. -The train ID system works by assigning the locomotive an ID of `1` and then assigning the remainder of the wagons 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**. -But then your friend had to connect two new wagons to the train and forgot to update the system! -Now the first two wagons in the `array` have to be moved to the back of the train, or everything will be out of order. -Your friend would be really grateful to you for fixing their mistake. +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` and the locomotive is added to the front. +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. ```javascript eachWagonsID = [2, 5, 1, 7, 4, 12, 6, 3, 13]; From 166a823d714572b15a4eb717fcadeba38fc6cc12 Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 29 Dec 2022 12:54:56 +0100 Subject: [PATCH 18/23] Runned prettier and aded hints --- exercises/concept/train-driver/.docs/hints.md | 17 +- .../train-driver/.docs/instructions.md | 10 +- .../train-driver/.docs/introduction.md | 22 +-- .../concept/train-driver/.meta/config.json | 2 +- .../concept/train-driver/.meta/design.md | 61 ++----- .../concept/train-driver/.meta/exemplar.js | 6 +- exercises/concept/train-driver/package.json | 2 +- .../concept/train-driver/train-driver.spec.js | 168 +++++++++++++----- 8 files changed, 165 insertions(+), 123 deletions(-) diff --git a/exercises/concept/train-driver/.docs/hints.md b/exercises/concept/train-driver/.docs/hints.md index deb481bb05..099b4746fd 100644 --- a/exercises/concept/train-driver/.docs/hints.md +++ b/exercises/concept/train-driver/.docs/hints.md @@ -1,21 +1,28 @@ # Hints -## 1. Create a list of all wagons +## General + +- To extract multiple arguments in the function parameters so can you pack them with the `...`. +- To use rest and spread use the `...` operator. +## 1. Create a list of all wagons +- Multiple arguments in the function parameters can be packed with the `...` operator. ## 2. Move the first two elements to the end of the array - +- Using unpacking with the rest operator(`...`), lets you extract the first two elements of a `array` while keeping the rest intact. +- To add another `array` into an existing `array`, you can use the `...` operator to "spread" the `array`. ## 3. Add missing values - +- Using unpacking with the rest operator(`...`), lets you extract the first two elements of a `array` while keeping the rest intact. +- To add another `array` into an existing `array`, you can use the `...` operator to "spread" the `array`. ## 4. Extend routing information - +- To add another `object` into an existing `object`, you can use the `...` operator to "spread" the `object`. ## 5. Separate arrival time from routing information - +- To extract a value from an `object` while keeping the rest intact, you can use the rest operator(`...`). diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 13f25507c9..68146f6e48 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -43,7 +43,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 @@ -70,8 +70,8 @@ The variable `moreRouteInformation` can contain different properties. ``` ```javascript -route = {from: "Berlin", to: "Hamburg"}; -moreRouteInformation = {length: "100", speed: "50"}; +route = { from: "Berlin", to: "Hamburg" }; +moreRouteInformation = { length: "100", speed: "50" }; extendRouteInformation(route, moreRouteInformation); // => {from: "Berlin", to: "Hamburg", length: "100", speed: "50"} ``` @@ -85,11 +85,11 @@ Implement a function `separateArrivalTime` that accepts an object with the routi 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 -routeInformation= { +routeInformation = { from: "Berlin", to: "Hamburg", length: "100", - timeOfArrival: "10:10" + timeOfArrival: "10:10", }; separateTimeOfArrival(routeInformation); // => ["10:10", {from: "Berlin", to: "Hamburg", length: "100"}] diff --git a/exercises/concept/train-driver/.docs/introduction.md b/exercises/concept/train-driver/.docs/introduction.md index 545afa161f..b8b27892a8 100644 --- a/exercises/concept/train-driver/.docs/introduction.md +++ b/exercises/concept/train-driver/.docs/introduction.md @@ -30,9 +30,9 @@ Similarly to arrays, the rest operator can also be used to collect one or more o ```javascript const { street, ...address } = { - street: 'Platz der Republik 1', - postalCode: '11011', - city: 'Berlin', + street: "Platz der Republik 1", + postalCode: "11011", + city: "Berlin", }; street; // => 'Platz der Republik 1' @@ -46,11 +46,11 @@ When `...` appears in a function definition next to its last argument, that para ```javascript function concat(...strings) { - return strings.join(' '); + return strings.join(" "); } -concat('one'); +concat("one"); // => 'one' -concat('one', 'two', 'three'); +concat("one", "two", "three"); // => 'one two three' ``` @@ -65,7 +65,7 @@ const oneToFive = [1, 2, 3, 4, 5]; const oneToTen = [...oneToFive, 6, 7, 8, 9, 10]; oneToTen; // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -const woow = ['A', ...oneToFive, 'B', 'C', 'D', 'E', ...oneToFive, 42]; +const woow = ["A", ...oneToFive, "B", "C", "D", "E", ...oneToFive, 42]; woow; // => ["A", 1, 2, 3, 4, 5, "B", "C", "D", "E", 1, 2, 3, 4, 5, 42] ``` @@ -76,13 +76,13 @@ Similarly to arrays, the spread operator can also be used to copy properties fro ```javascript let address = { - postalCode: '11011', - city: 'Berlin', + postalCode: "11011", + city: "Berlin", }; -address = { ...address, country: 'Germany' }; +address = { ...address, country: "Germany" }; // => { // postalCode: '11011', // city: 'Berlin', // country: 'Germany', // } -``` \ No newline at end of file +``` diff --git a/exercises/concept/train-driver/.meta/config.json b/exercises/concept/train-driver/.meta/config.json index fd1c5906d3..b771267146 100644 --- a/exercises/concept/train-driver/.meta/config.json +++ b/exercises/concept/train-driver/.meta/config.json @@ -1,6 +1,6 @@ { "authors": [ - "meatball" + "meatball133" ], "contributors": [ "bethanyg", diff --git a/exercises/concept/train-driver/.meta/design.md b/exercises/concept/train-driver/.meta/design.md index 554e26f2c7..3d9bd201fd 100644 --- a/exercises/concept/train-driver/.meta/design.md +++ b/exercises/concept/train-driver/.meta/design.md @@ -2,60 +2,23 @@ ## Learning objectives -- What does a for loop do -- Syntax `for(...){...}` -- What are the different parts of the for loop header -- How to iterate over an array with a for loop -- What is the increment/decrement operator `i++`/`i--` +- Using spread to turn an array into a list of parameters +- Using rest elements to turn a list of parameters into an array +- Using spread to turn an extract value out of an object +- Using spread to combine objects +- Using rest to collect multiple parameters into an array -## Out of Scope +## Out of scope -The following topics are out of scope because they are covered by another concept exercise. - -- Other loops like `while` -- Other possibilities of iterating over an array -- `break` and `continue` are only mentioned in the about.md file here because they will be more in focus in the `while` exercise +- Default values ## Concepts -The Concepts this exercise unlocks are: - -- `for-loops` -- `increment-decrement` +- `rest-and-spread` ## Prerequisites -- `arrays` because they are used to iterate over them in the exercise -- `comparison` for writing the condition in the loop header -- `conditionals` because they introduced the student to the concept of conditional execution - -## Analyzer - -This exercise could benefit from the following rules in the [analyzer][analyzer]: - -For all tasks check that the student actually used a for loop. - -1. `totalBirdCount` - - - Verify that the condition is written with `< x.length` instead of `<= y.length -1`. - - Check whether a shorthand assignment `+=` was used to increase the sum (non-essential feedback). - - Verify the total was properly initialized with `0` instead of e.g. `null` - - Verify the increment operator was used in loop header step - -2. `birdsInWeek` - - - Verify a helper variable was used instead of duplicating the calculation in the initialization and condition of the loop - - Other checks should be the same as for `totalBirdCount` - -3. `fixBirdCountLog` - - - Check whether a shorthand assignment `+=` was used to increase the loop counter (non-essential feedback) - - Check whether the increment operator was used in the loop body - -## Notes - -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. -Since the exercise for the JavaScript track should be focussed on the for loop, the tasks where reduced and changed accordingly. - -[analyzer]: https://github.com/exercism/javascript-analyzer -[csharp-bird-watcher]: https://github.com/exercism/csharp/blob/main/exercises/concept/bird-watcher/.docs/instructions.md +- `arrays` are needed to understand array restructuring +- `functions` are needed as basis for rest parameters +- `objects` are needed for object spread etc. +- `array-destructuring` are needed to understand rest elements diff --git a/exercises/concept/train-driver/.meta/exemplar.js b/exercises/concept/train-driver/.meta/exemplar.js index 311f34709c..8588849b45 100644 --- a/exercises/concept/train-driver/.meta/exemplar.js +++ b/exercises/concept/train-driver/.meta/exemplar.js @@ -10,8 +10,8 @@ * @param {number[]} eachWagonsID * @returns {number[]} each Wagons Wiegth */ - export function getListOfWagons(...eachWagonsID) { - return eachWagonsID +export function getListOfWagons(...eachWagonsID) { + return eachWagonsID; } /** @@ -57,4 +57,4 @@ export function extendRouteInformation(route, moreRouteInformation) { export function separateTimeOfArrival(route) { const { timeOfArrival, ...rest } = route; return [timeOfArrival, rest]; -} \ No newline at end of file +} diff --git a/exercises/concept/train-driver/package.json b/exercises/concept/train-driver/package.json index f6b7f194f6..8134115b35 100644 --- a/exercises/concept/train-driver/package.json +++ b/exercises/concept/train-driver/package.json @@ -1,7 +1,7 @@ { "name": "@exercism/javascript-train-driver", "description": "Exercism concept exercise on rest and spread operators", - "author": "Meatball", + "author": "Meatball133", "private": true, "license": "MIT", "repository": { diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js index 4ad8f5736c..16b4ba6f25 100644 --- a/exercises/concept/train-driver/train-driver.spec.js +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -1,57 +1,67 @@ -import { getListOfWagons, fixListOfWagons, correctListOfWagons, extendRouteInformation, separateTimeOfArrival } from './train-driver'; +import { + getListOfWagons, + fixListOfWagons, + correctListOfWagons, + extendRouteInformation, + separateTimeOfArrival, +} from "./train-driver"; -describe('getListOfWagons', () => { - test('return the correct array', () => { - expect(getListOfWagons(1,5,2,7,4)).toEqual([1,5,2,7,4]); +describe("getListOfWagons", () => { + test("return the correct array", () => { + expect(getListOfWagons(1, 5, 2, 7, 4)).toEqual([1, 5, 2, 7, 4]); }); - test('works for a few arrgument', () => { - expect(getListOfWagons(1,5)).toEqual([1,5]); + test("works for a few arrgument", () => { + expect(getListOfWagons(1, 5)).toEqual([1, 5]); }); - test('works for a one arrgument', () => { + test("works for a one arrgument", () => { expect(getListOfWagons(1)).toEqual([1]); }); - test('works for many argument', () => { - expect(getListOfWagons(1,5,6,3,9,8,4,14,24,7)).toEqual([1,5,6,3,9,8,4,14,24,7]); + test("works for many argument", () => { + expect(getListOfWagons(1, 5, 6, 3, 9, 8, 4, 14, 24, 7)).toEqual([ + 1, 5, 6, 3, 9, 8, 4, 14, 24, 7, + ]); }); }); -describe('fixListOfWagons', () => { - test('reorder the first 2 wagons to the end of the array', () => { +describe("fixListOfWagons", () => { + test("reorder the first 2 wagons to the end of the array", () => { const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19]; const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7]; expect(fixListOfWagons(eachWagonsID)).toEqual(expected); }); - test('works when only 3 wagons given', () => { + test("works when only 3 wagons given", () => { const eachWagonsID = [4, 2, 1]; expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]); }); - test('works for a few wagons', () => { + test("works for a few wagons", () => { const eachWagonsID = [3, 4, 1, 5, 7, 9, 10]; expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]); }); }); -describe('correctListOfWagons', () => { - test('returns a wagon wieght list with the inserted array of values', () => { +describe("correctListOfWagons", () => { + test("returns a wagon wieght list with the inserted array of values", () => { const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; const missingWagons = [8, 10, 5, 9, 3, 7, 20]; - const expected = [1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; + const expected = [ + 1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21, + ]; expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); - test('works for short arrays', () => { + test("works for short arrays", () => { const eachWagonsID = [1, 7, 15, 24]; const missingWagons = [8, 6, 4]; const expected = [1, 8, 6, 4, 7, 15, 24]; expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); - test('works when missingWagons is longer', () => { + test("works when missingWagons is longer", () => { const eachWagonsID = [1, 7, 15, 24]; const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13]; const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24]; @@ -59,45 +69,107 @@ describe('correctListOfWagons', () => { }); }); -describe('extendRouteInformation', () => { - test('correctly extend route information', () => { - const route = {from: "Berlin", to: "Hamburg"}; - const moreRouteInformation = {timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; - const expected = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; - expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); - }); - - test('works when not adding precipitation', () => { - const route = {from: "Paris", to: "London"}; - const moreRouteInformation = {timeOfArrival: "10:30", temperature: "20"}; - const expected = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; - expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); - }); - - test('works when written in diffrent order', () => { - const route = {from: "Gothenburg", to: "Copenhagen"}; - const moreRouteInformation = {precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; - const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; - expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); +describe("extendRouteInformation", () => { + test("correctly extend route information", () => { + const route = { from: "Berlin", to: "Hamburg" }; + const moreRouteInformation = { + timeOfArrival: "12:00", + precipitation: "10", + temperature: "5", + }; + const expected = { + from: "Berlin", + to: "Hamburg", + timeOfArrival: "12:00", + precipitation: "10", + temperature: "5", + }; + expect(extendRouteInformation(route, moreRouteInformation)).toEqual( + expected + ); + }); + + test("works when not adding precipitation", () => { + const route = { from: "Paris", to: "London" }; + const moreRouteInformation = { timeOfArrival: "10:30", temperature: "20" }; + const expected = { + from: "Paris", + to: "London", + timeOfArrival: "10:30", + temperature: "20", + }; + expect(extendRouteInformation(route, moreRouteInformation)).toEqual( + expected + ); + }); + + test("works when written in diffrent order", () => { + const route = { from: "Gothenburg", to: "Copenhagen" }; + const moreRouteInformation = { + precipitation: "1", + timeOfArrival: "21:20", + temperature: "-6", + }; + const expected = { + from: "Gothenburg", + to: "Copenhagen", + precipitation: "1", + timeOfArrival: "21:20", + temperature: "-6", + }; + expect(extendRouteInformation(route, moreRouteInformation)).toEqual( + expected + ); }); }); -describe('separateTimeOfArrival', () => { - test('seperate timeOfArrival from object', () => { - const route = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"}; - const expected = ["12:00", {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}] +describe("separateTimeOfArrival", () => { + test("seperate timeOfArrival from object", () => { + const route = { + from: "Berlin", + to: "Hamburg", + timeOfArrival: "12:00", + precipitation: "10", + temperature: "5", + }; + const expected = [ + "12:00", + { from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5" }, + ]; expect(separateTimeOfArrival(route)).toEqual(expected); }); - test('seperate timeOfArrival with shorter object', () => { - const route = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"}; - const expected = ["10:30", {from: "Paris", to: "London", temperature: "20"}] + test("seperate timeOfArrival with shorter object", () => { + const route = { + from: "Paris", + to: "London", + timeOfArrival: "10:30", + temperature: "20", + }; + const expected = [ + "10:30", + { from: "Paris", to: "London", temperature: "20" }, + ]; expect(separateTimeOfArrival(route)).toEqual(expected); }); - test('seperate timeOfArrival from object', () => { - const route = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"}; - const expected = ["21:20", {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}] + test("seperate timeOfArrival from object", () => { + const route = { + from: "Gothenburg", + to: "Copenhagen", + precipitation: "1", + timeOfArrival: "21:20", + temperature: "-6", + }; + const expected = [ + "21:20", + { + from: "Gothenburg", + to: "Copenhagen", + precipitation: "1", + temperature: "-6", + }, + ]; expect(separateTimeOfArrival(route)).toEqual(expected); }); }); From 47f0ffee8b377b1f60509271a56878c21e060b46 Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 29 Dec 2022 12:59:27 +0100 Subject: [PATCH 19/23] Runed babel --- exercises/concept/train-driver/package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/concept/train-driver/package.json b/exercises/concept/train-driver/package.json index 8134115b35..09bc9d8e3c 100644 --- a/exercises/concept/train-driver/package.json +++ b/exercises/concept/train-driver/package.json @@ -10,15 +10,15 @@ "directory": "exercises/concept/train-driver" }, "devDependencies": { - "@babel/core": "^7.19.6", + "@babel/core": "^7.20.2", "@exercism/babel-preset-javascript": "^0.2.1", "@exercism/eslint-config-javascript": "^0.6.0", - "@types/jest": "^29.2.0", - "@types/node": "^18.11.0", + "@types/jest": "^29.2.2", + "@types/node": "^18.11.9", "babel-jest": "^29.2.2", "core-js": "~3.26.0", - "eslint": "^8.26.0", - "jest": "^29.2.1" + "eslint": "^8.27.0", + "jest": "^29.3.1" }, "dependencies": {}, "scripts": { From 96c8bcbd6e684f5f08c97417c83806b139624080 Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 29 Dec 2022 13:00:21 +0100 Subject: [PATCH 20/23] runed babel again --- exercises/concept/train-driver/package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/concept/train-driver/package.json b/exercises/concept/train-driver/package.json index 09bc9d8e3c..9474fb28fc 100644 --- a/exercises/concept/train-driver/package.json +++ b/exercises/concept/train-driver/package.json @@ -10,14 +10,14 @@ "directory": "exercises/concept/train-driver" }, "devDependencies": { - "@babel/core": "^7.20.2", + "@babel/core": "^7.20.7", "@exercism/babel-preset-javascript": "^0.2.1", "@exercism/eslint-config-javascript": "^0.6.0", - "@types/jest": "^29.2.2", - "@types/node": "^18.11.9", + "@types/jest": "^29.2.4", + "@types/node": "^18.11.17", "babel-jest": "^29.2.2", - "core-js": "~3.26.0", - "eslint": "^8.27.0", + "core-js": "~3.26.1", + "eslint": "^8.30.0", "jest": "^29.3.1" }, "dependencies": {}, From a5fef2f660cf96940200f0f4ad40bcf9fb790115 Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 29 Dec 2022 13:02:00 +0100 Subject: [PATCH 21/23] Runned prettier again --- .../train-driver/.docs/instructions.md | 12 +- .../train-driver/.docs/introduction.md | 20 +-- .../concept/train-driver/train-driver.js | 2 +- .../concept/train-driver/train-driver.spec.js | 138 +++++++++--------- 4 files changed, 86 insertions(+), 86 deletions(-) diff --git a/exercises/concept/train-driver/.docs/instructions.md b/exercises/concept/train-driver/.docs/instructions.md index 68146f6e48..6c466db264 100644 --- a/exercises/concept/train-driver/.docs/instructions.md +++ b/exercises/concept/train-driver/.docs/instructions.md @@ -70,8 +70,8 @@ The variable `moreRouteInformation` can contain different properties. ``` ```javascript -route = { from: "Berlin", to: "Hamburg" }; -moreRouteInformation = { length: "100", speed: "50" }; +route = { from: 'Berlin', to: 'Hamburg' }; +moreRouteInformation = { length: '100', speed: '50' }; extendRouteInformation(route, moreRouteInformation); // => {from: "Berlin", to: "Hamburg", length: "100", speed: "50"} ``` @@ -86,10 +86,10 @@ The function should return an array there the first element of the array is the ```javascript routeInformation = { - from: "Berlin", - to: "Hamburg", - length: "100", - timeOfArrival: "10:10", + from: 'Berlin', + to: 'Hamburg', + length: '100', + timeOfArrival: '10:10', }; separateTimeOfArrival(routeInformation); // => ["10:10", {from: "Berlin", to: "Hamburg", length: "100"}] diff --git a/exercises/concept/train-driver/.docs/introduction.md b/exercises/concept/train-driver/.docs/introduction.md index b8b27892a8..53dbcfa7be 100644 --- a/exercises/concept/train-driver/.docs/introduction.md +++ b/exercises/concept/train-driver/.docs/introduction.md @@ -30,9 +30,9 @@ Similarly to arrays, the rest operator can also be used to collect one or more o ```javascript const { street, ...address } = { - street: "Platz der Republik 1", - postalCode: "11011", - city: "Berlin", + street: 'Platz der Republik 1', + postalCode: '11011', + city: 'Berlin', }; street; // => 'Platz der Republik 1' @@ -46,11 +46,11 @@ When `...` appears in a function definition next to its last argument, that para ```javascript function concat(...strings) { - return strings.join(" "); + return strings.join(' '); } -concat("one"); +concat('one'); // => 'one' -concat("one", "two", "three"); +concat('one', 'two', 'three'); // => 'one two three' ``` @@ -65,7 +65,7 @@ const oneToFive = [1, 2, 3, 4, 5]; const oneToTen = [...oneToFive, 6, 7, 8, 9, 10]; oneToTen; // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -const woow = ["A", ...oneToFive, "B", "C", "D", "E", ...oneToFive, 42]; +const woow = ['A', ...oneToFive, 'B', 'C', 'D', 'E', ...oneToFive, 42]; woow; // => ["A", 1, 2, 3, 4, 5, "B", "C", "D", "E", 1, 2, 3, 4, 5, 42] ``` @@ -76,10 +76,10 @@ Similarly to arrays, the spread operator can also be used to copy properties fro ```javascript let address = { - postalCode: "11011", - city: "Berlin", + postalCode: '11011', + city: 'Berlin', }; -address = { ...address, country: "Germany" }; +address = { ...address, country: 'Germany' }; // => { // postalCode: '11011', // city: 'Berlin', diff --git a/exercises/concept/train-driver/train-driver.js b/exercises/concept/train-driver/train-driver.js index da40852ced..d7c06e9c26 100644 --- a/exercises/concept/train-driver/train-driver.js +++ b/exercises/concept/train-driver/train-driver.js @@ -54,4 +54,4 @@ export function extendRouteInformation(route, moreRouteInformation) { */ export function separateTimeOfArrival(route) { throw new Error('Please implement the separateTimeOfArrival function'); -} \ No newline at end of file +} diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js index 16b4ba6f25..eaf921cd22 100644 --- a/exercises/concept/train-driver/train-driver.spec.js +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -4,48 +4,48 @@ import { correctListOfWagons, extendRouteInformation, separateTimeOfArrival, -} from "./train-driver"; +} from './train-driver'; -describe("getListOfWagons", () => { - test("return the correct array", () => { +describe('getListOfWagons', () => { + test('return the correct array', () => { expect(getListOfWagons(1, 5, 2, 7, 4)).toEqual([1, 5, 2, 7, 4]); }); - test("works for a few arrgument", () => { + test('works for a few arrgument', () => { expect(getListOfWagons(1, 5)).toEqual([1, 5]); }); - test("works for a one arrgument", () => { + test('works for a one arrgument', () => { expect(getListOfWagons(1)).toEqual([1]); }); - test("works for many argument", () => { + test('works for many argument', () => { expect(getListOfWagons(1, 5, 6, 3, 9, 8, 4, 14, 24, 7)).toEqual([ 1, 5, 6, 3, 9, 8, 4, 14, 24, 7, ]); }); }); -describe("fixListOfWagons", () => { - test("reorder the first 2 wagons to the end of the array", () => { +describe('fixListOfWagons', () => { + test('reorder the first 2 wagons to the end of the array', () => { const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19]; const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7]; expect(fixListOfWagons(eachWagonsID)).toEqual(expected); }); - test("works when only 3 wagons given", () => { + test('works when only 3 wagons given', () => { const eachWagonsID = [4, 2, 1]; expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]); }); - test("works for a few wagons", () => { + test('works for a few wagons', () => { const eachWagonsID = [3, 4, 1, 5, 7, 9, 10]; expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]); }); }); -describe("correctListOfWagons", () => { - test("returns a wagon wieght list with the inserted array of values", () => { +describe('correctListOfWagons', () => { + test('returns a wagon wieght list with the inserted array of values', () => { const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; const missingWagons = [8, 10, 5, 9, 3, 7, 20]; const expected = [ @@ -54,14 +54,14 @@ describe("correctListOfWagons", () => { expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); - test("works for short arrays", () => { + test('works for short arrays', () => { const eachWagonsID = [1, 7, 15, 24]; const missingWagons = [8, 6, 4]; const expected = [1, 8, 6, 4, 7, 15, 24]; expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); }); - test("works when missingWagons is longer", () => { + test('works when missingWagons is longer', () => { const eachWagonsID = [1, 7, 15, 24]; const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13]; const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24]; @@ -69,53 +69,53 @@ describe("correctListOfWagons", () => { }); }); -describe("extendRouteInformation", () => { - test("correctly extend route information", () => { - const route = { from: "Berlin", to: "Hamburg" }; +describe('extendRouteInformation', () => { + test('correctly extend route information', () => { + const route = { from: 'Berlin', to: 'Hamburg' }; const moreRouteInformation = { - timeOfArrival: "12:00", - precipitation: "10", - temperature: "5", + timeOfArrival: '12:00', + precipitation: '10', + temperature: '5', }; const expected = { - from: "Berlin", - to: "Hamburg", - timeOfArrival: "12:00", - precipitation: "10", - temperature: "5", + from: 'Berlin', + to: 'Hamburg', + timeOfArrival: '12:00', + precipitation: '10', + temperature: '5', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( expected ); }); - test("works when not adding precipitation", () => { - const route = { from: "Paris", to: "London" }; - const moreRouteInformation = { timeOfArrival: "10:30", temperature: "20" }; + test('works when not adding precipitation', () => { + const route = { from: 'Paris', to: 'London' }; + const moreRouteInformation = { timeOfArrival: '10:30', temperature: '20' }; const expected = { - from: "Paris", - to: "London", - timeOfArrival: "10:30", - temperature: "20", + from: 'Paris', + to: 'London', + timeOfArrival: '10:30', + temperature: '20', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( expected ); }); - test("works when written in diffrent order", () => { - const route = { from: "Gothenburg", to: "Copenhagen" }; + test('works when written in diffrent order', () => { + const route = { from: 'Gothenburg', to: 'Copenhagen' }; const moreRouteInformation = { - precipitation: "1", - timeOfArrival: "21:20", - temperature: "-6", + precipitation: '1', + timeOfArrival: '21:20', + temperature: '-6', }; const expected = { - from: "Gothenburg", - to: "Copenhagen", - precipitation: "1", - timeOfArrival: "21:20", - temperature: "-6", + from: 'Gothenburg', + to: 'Copenhagen', + precipitation: '1', + timeOfArrival: '21:20', + temperature: '-6', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( expected @@ -123,51 +123,51 @@ describe("extendRouteInformation", () => { }); }); -describe("separateTimeOfArrival", () => { - test("seperate timeOfArrival from object", () => { +describe('separateTimeOfArrival', () => { + test('seperate timeOfArrival from object', () => { const route = { - from: "Berlin", - to: "Hamburg", - timeOfArrival: "12:00", - precipitation: "10", - temperature: "5", + from: 'Berlin', + to: 'Hamburg', + timeOfArrival: '12:00', + precipitation: '10', + temperature: '5', }; const expected = [ - "12:00", - { from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5" }, + '12:00', + { from: 'Berlin', to: 'Hamburg', precipitation: '10', temperature: '5' }, ]; expect(separateTimeOfArrival(route)).toEqual(expected); }); - test("seperate timeOfArrival with shorter object", () => { + test('seperate timeOfArrival with shorter object', () => { const route = { - from: "Paris", - to: "London", - timeOfArrival: "10:30", - temperature: "20", + from: 'Paris', + to: 'London', + timeOfArrival: '10:30', + temperature: '20', }; const expected = [ - "10:30", - { from: "Paris", to: "London", temperature: "20" }, + '10:30', + { from: 'Paris', to: 'London', temperature: '20' }, ]; expect(separateTimeOfArrival(route)).toEqual(expected); }); - test("seperate timeOfArrival from object", () => { + test('seperate timeOfArrival from object', () => { const route = { - from: "Gothenburg", - to: "Copenhagen", - precipitation: "1", - timeOfArrival: "21:20", - temperature: "-6", + from: 'Gothenburg', + to: 'Copenhagen', + precipitation: '1', + timeOfArrival: '21:20', + temperature: '-6', }; const expected = [ - "21:20", + '21:20', { - from: "Gothenburg", - to: "Copenhagen", - precipitation: "1", - temperature: "-6", + from: 'Gothenburg', + to: 'Copenhagen', + precipitation: '1', + temperature: '-6', }, ]; expect(separateTimeOfArrival(route)).toEqual(expected); From c45f0ff3e3fe1ff4e6d4af54d1fe579737dca6b9 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Fri, 22 Sep 2023 21:41:46 +0200 Subject: [PATCH 22/23] Add links --- exercises/concept/train-driver/.docs/hints.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exercises/concept/train-driver/.docs/hints.md b/exercises/concept/train-driver/.docs/hints.md index 099b4746fd..a80b5c2af0 100644 --- a/exercises/concept/train-driver/.docs/hints.md +++ b/exercises/concept/train-driver/.docs/hints.md @@ -7,11 +7,12 @@ ## 1. Create a list of all wagons -- Multiple arguments in the function parameters can be packed with the `...` operator. +- Multiple arguments in the function parameters can be packed with the [`...` (spread) syntax][spread-syntax]. operator. ## 2. Move the first two elements to the end of the array -- Using unpacking with the rest operator(`...`), lets you extract the first two elements of a `array` while keeping the rest intact. +- You can unpack a series of parameters using [a destructuring assignment (`...`)][destructuring-assignment]. + This lets you extract the first two elements of a `array` while keeping the rest intact. - To add another `array` into an existing `array`, you can use the `...` operator to "spread" the `array`. ## 3. Add missing values @@ -26,3 +27,6 @@ ## 5. Separate arrival time from routing information - To extract a value from an `object` while keeping the rest intact, you can use the rest operator(`...`). + +[spread-syntax]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax +[destructuring-assignment]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment From c48bd2721d2e8a66873fc3eaf4c41490e701dd87 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:49:41 +0000 Subject: [PATCH 23/23] Sync and format --- exercises/concept/train-driver/.gitignore | 8 +++++--- exercises/concept/train-driver/package.json | 14 +++++++------- .../concept/train-driver/train-driver.spec.js | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/exercises/concept/train-driver/.gitignore b/exercises/concept/train-driver/.gitignore index bdb912f98a..31c57dd53a 100644 --- a/exercises/concept/train-driver/.gitignore +++ b/exercises/concept/train-driver/.gitignore @@ -1,3 +1,5 @@ -node_modules -yarn-error.log - +/node_modules +/bin/configlet +/bin/configlet.exe +/pnpm-lock.yaml +/yarn.lock diff --git a/exercises/concept/train-driver/package.json b/exercises/concept/train-driver/package.json index 9474fb28fc..bc59ec8446 100644 --- a/exercises/concept/train-driver/package.json +++ b/exercises/concept/train-driver/package.json @@ -10,15 +10,15 @@ "directory": "exercises/concept/train-driver" }, "devDependencies": { - "@babel/core": "^7.20.7", + "@babel/core": "^7.22.10", "@exercism/babel-preset-javascript": "^0.2.1", "@exercism/eslint-config-javascript": "^0.6.0", - "@types/jest": "^29.2.4", - "@types/node": "^18.11.17", - "babel-jest": "^29.2.2", - "core-js": "~3.26.1", - "eslint": "^8.30.0", - "jest": "^29.3.1" + "@types/jest": "^29.5.4", + "@types/node": "^20.5.6", + "babel-jest": "^29.6.4", + "core-js": "~3.32.1", + "eslint": "^8.49.0", + "jest": "^29.6.3" }, "dependencies": {}, "scripts": { diff --git a/exercises/concept/train-driver/train-driver.spec.js b/exercises/concept/train-driver/train-driver.spec.js index eaf921cd22..fca6d1cc5b 100644 --- a/exercises/concept/train-driver/train-driver.spec.js +++ b/exercises/concept/train-driver/train-driver.spec.js @@ -85,7 +85,7 @@ describe('extendRouteInformation', () => { temperature: '5', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( - expected + expected, ); }); @@ -99,7 +99,7 @@ describe('extendRouteInformation', () => { temperature: '20', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( - expected + expected, ); }); @@ -118,7 +118,7 @@ describe('extendRouteInformation', () => { temperature: '-6', }; expect(extendRouteInformation(route, moreRouteInformation)).toEqual( - expected + expected, ); }); });