javascript
javascript copied to clipboard
Separate `rest-and-spread` into its own new concept exercise (concept exists)
Getting started
Here you can read about what Concept Exercises are and how they are structured:
If you have not done so yet, it is probably also helpful to do a couple of "Learning Exercises" (this is how they are called on the site) yourself. You can also look at the code of an existing concept exercise like bird-watcher
(concept for-loops
) for reference.
Goal
The goal is to create new concept exercise that teaches the use of the rest and spread operator in the context of functions (rest parameters), arrays and objects.
Motivation
Currently, the concept exercise "Elyses Destructered Enchantments" teaches array destructing and the rest and spread operator (...
) which also includes object related content. In the future we also want to teach object destructering as a concept. Since it would be too much to also add that into the same exercise, we want to have a new split. In the future, we want to change "Elyses Destructered Enchantments" so that it focuses on array and object destructering in the context of extracting individual elements/properties. In turn, rest and spread should be covered by a new exercise that the student will complete after "Elyses Destructered Enchantments".
Please note that updating the existing exercise "Elyses Destructered Enchantments" is out of scope for this issue. There will be a separate issue for that later.
Concepts
The concept rest-and-spread
already exists but feel free to improve the content or add more advanced content to the about.md file as you see fit.
https://github.com/exercism/javascript/tree/main/concepts/rest-and-spread
Learning Objectives
The student should learn what is covered in the existing concept: https://github.com/exercism/javascript/blob/main/concepts/rest-and-spread/introduction.md
Prerequisites
The following things should be assumed and defined as prerequisites for the exercise.
-
functions
-
array-destructering
(in the context of extracting individual elements, no rest operator) - Although this concept is not available yet, you can assume the student also already knows about object destructering (in the context of extracting individual properties)
Story
Here some hints what can help to come up with a story for the exercise.
- Think about/write down some tasks you would like the student to do (just generic tasks, no story), sometimes that already sparks an idea for a story to wrap the tasks.
- Browse through the existing stories https://exercism.org/docs/building/tracks/stories (click on the individual story in the menu on the left), usually you won't find an exact match but some story might spark your inspiration for some general theme.
- In the end, you can make nearly every story fit every concept so just picking some theme and rolling with it also works.
Help
You can choose to do this solo-style, or collaborate with multiple people on this. The suggested approach is to
- First accept this issue by saying "I'd like to work on this" (no need to wait for a response, just go with it) and optionally request that someone works with you (and wait for a second person to accept your request).
- Use this issue to discuss any questions you have, what should be included in the content and what not and to collect reference material.
- Create a PR and set "exercism/javascript" as reviewers. Additionally you can write in #maintaining-javascript that your PR is ready for review. Once you incorporated any critical feedback that the reviewer might give you and the PR is approved, it will be merged by a maintainer.
Hi, this would be my first time writing an exercise. Although I like to give it a shot if some one wants to work together on this I am happy to do so. Although I like to claim it
@meatball133 I will assign you to this issues. It is quite a challenging task so leave a comment in case you decide not to continue with it at some point.
Well, I have come up with some kind of story and would like to hear what you think.
So you have a friend who is a bird watcher. They aren't that good at handling computer data and would like your help.
The first exercise is to convert a number of inputs to an array:
getListOfBirds(5, 7, 12, 3, 14, 8, 3);
// => [5, 7, 12, 3, 14, 8, 3]
//solution:
function getListOfBirds(...birds){
return birds
}
The second one is to move the first 2 elements to the end of an array:
birdsPerDay = [2, 5, 0, 7, 4, 0, 1, 3, 1];
fixListOfBirds(birdsPerDay);
// => [0, 7, 4, 0, 1, 3, 1, 2, 5]
//solution:
function fixListOfBirds(birds){
const [a, b, ...rest] = birds
return [...rest,a,b]
}
The third one is to add an array of elements after the first element in an array:
birdsPerDay = [2, 5, 0, 7, 4, 1];
missingBirds = [3, 0, 6, 1];
CorrectListOfBirds(birdsPerDay, missingBirds);
// => [2, 3, 0, 6, 1, 5, 0, 7, 4, 1]
//solution:
function CorrectListOfBirds(birds, missing){
const [a, ...rest] = birds
return [a, ...missing, ...rest]
}
Is these good exercises or should they be more advanced and is there anything I could improve?
Looks like good start, two thoughts on this:
- Can you double check you covered the points linked above under "learning objectives"? It looks like the object parts are missing.
- There is already an exercise called "bird watcher" in the JavaScript track so maybe the theme can be changed a bit to not repeat itself, e.g. it could be about observing traffic on a street instead of watching birds.
Yes I can add 1-2 more exercises that covers object. I will also look into having a bit different theme aswell. Thanks for the feedback
Alright, new story you are suppose to help your friend who is a train driver. One element in an array should represent one wagon and the number in it represents the wieght of the wagon.
The fourth exercise is to add missing information to the trains routing system.
route = "cityX - cityZ";
missingRouteInformation = {
length: 100,
timeOfArrival: "10:10"
};
addMissingRouteInfo(route, missingRouteInformation);
// => {route: "cityX - cityZ", length: 100, timeOfArrival: "10:10"}
//solution:
function addMissingRouteInfo(route, missingRouteInformation){
return {route, ...missingRouteInformation}
}
The fifth exercise is to remove timeOfArrival element of the object.
routeInformation= {
route: "cityX - cityZ",
length: 100,
timeOfArrival: "10:10"
};
removeTimeOfArrival(routeInformation);
// => {route: "cityX - cityZ", length: 100}
//solution:
function removeTimeOfArrival(routeInformation){
const timeOfArrival, ...restOfInformation = routeInformation
return restOfInformation
}
I would very much appricate feedback and I would personally say this covers all of the topics in the syllabus.
Added a first iteration of the files. I would like to get some feedback this far and then I will continue to finish up the rest.