This issue describes how to implement the array-destructuring concept exercise for the javascript track.
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
See the documentation _above_ (general documentation), as well as How to implement a Concept Exercise in JavaScript.
The goal of this exercise is to teach the student how they can _destructure_ an array into multiple bindings.
array-destructuringspread-elementsrest-elements@ErikSchierboom please advice. These are three concepts, which can be used on their own, but not when learning/teaching. It makes absolute sense to have them _separately_ for exercises, but not when teaching the concept itself.
However, we _could_ argue that, because you learn them all together here, that for us it's just 'one concept'. In that case, I need help with the name (probably still array-descructuring). The counter part is object-destructuring).
arraysArray-destructuring.[first, [, nestedSecond]])You can choose to do this solo-style, or collaborate with multiple people on this. My suggestion would be is to
@ErikSchierboom please advice. These are three concepts, which can be used on their own, but not when learning/teaching. It makes absolute sense to have them separately for exercises, but not when teaching the concept itself.
However, we could argue that, because you learn them all together here, that for us it's just 'one concept'. In that case, I need help with the name (probably still array-descructuring). The counter part is object-destructuring).
@SleeplessByte I'd have the exercise be named after the primary concept (which looks to be array-destructuring) and have it unlock three concepts: array-destructuring, spread-elements and rest-elements
Is there a recommended story for this one?
No idea. @SleeplessByte?
All array exercises should probably be the same magician thing :paintbrush:
I'd like to work on this, assuming @joshgoebel hasn't taken it?
@kristinaborn Go for it.
@kristinaborn you can take it!
I'd like to work on this considering @kristinaborn isn't working on it?
@shubhsk88 I've been chipping away at it. Should be able to get a draft PR up this weekend.
Nearly done, but I'm missing task coverage for a couple of the learning objectives because they don't totally make sense to me. @SleeplessByte perhaps you could clarify?
"Using destructuring to get the first two items of an array" -- how is this different from the "Using destructuring to get the first item of an array" objective?
"Using destructuring + rest elements to get the last item of an array" -- maybe I'm missing something, but this seems odd. What's the use case for breaking out rest syntax to retrieve a single item? Wouldn't you always just use a regular variable?
const [first] = items
const [, second] = items
const [first, second] = items
# this doesn't work on JavaScript, but works in
# many other languages
const [_..., last] = items
You don't need to teach everything individually. And maybe something is impossible to teach.
Let met know if you have ideas!
Calling out the difference in the way rest works vs. other languages is definitely a good point. Trying to teach that via a task would be awkward, so I'll discuss it in the after doc instead.
@SleeplessByte shouldn't this be closed?
Yep! Thanks @henricazottes