question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

curriculum: Need a more robust way to test for destructuring in the Use Destructuring Assignment to Assign Variables from Arrays challenge

See original GitHub issue

Per this forum topic, it was discovered our test for detecting destructuring, is not very flexible

Link to challenge

For example, the following should pass as the current challenge is written.

let a = 8, b = 6;
// change code below this line
let arr = [a, b];
[b, a] = arr;

// change code above this line
console.log(a); // should be 6
console.log(b); // should be 8

My first thought was to change the instructions to state something like:

Use destructuring assignment to swap the values of a and b so that a receives the value stored in b, and b receives the value stored in a. Do not create any additional variables to solve this challenge.

While that would deal with the above code being used, it would not deal with something like:

let a = 8, b = 6;
// change code below this line
[b, a] = Array(a,b); // or [b, a] = [a].concat(b);

// change code above this line
console.log(a); // should be 6
console.log(b); // should be 8

Anyone have any thoughts on how best to change this challenge’s instructions and/or test?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
moT01commented, Jan 13, 2020

No, nothing is wrong @ShubhamCanMakeCommit. That sounds similar to my “easier” suggestion. I would be fine fixing it like this.

0reactions
moT01commented, Jul 20, 2021

Thank you for reporting this issue.

This is a standard message notifying you that the issue has become stale, so we are going to close it.

If you think we’re wrong in closing this issue, please request for it to be reopened. Thank you and happy coding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Destructuring Assignment to Assign Variables from Arrays ...
In this JavaScript ES6 tutorial we use destructuring assignment to assign variables from arrays. This is one part of a multi-part series ...
Read more >
ES6 - Use Destructuring Assignment to Assign Variables from ...
ES6 - Use Destructuring Assignment to Assign Variables from Arrays - Free Code Camp · How to Use the Rest Parameter with Function...
Read more >
How to Use the Destructuring Assignment to Assign Variables ...
By watching this video, you will learn how to use the destructuring assignment to assign variables from array elements.
Read more >
Why is this useful? : destructuring assignment to assign ...
I've completed the challenge correctly, but I feel like the test example is more confusing than the description.
Read more >
Functions - Julia Documentation
Function arguments themselves act as new variable bindings (new locations that can refer to values), but the values they refer to are identical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found