Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update title and text from rest parameter to rest property (or element) #47473

Closed
lasjorg opened this issue Sep 8, 2022 · 9 comments · Fixed by #48793
Closed

Update title and text from rest parameter to rest property (or element) #47473

lasjorg opened this issue Sep 8, 2022 · 9 comments · Fixed by #48793
Labels
first timers only Open for anyone doing contributions for first time. You do not need permission to work on these. scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.

Comments

@lasjorg
Copy link
Contributor

lasjorg commented Sep 8, 2022

Describe the Issue

A rest parameter would involve parameters.

The MDN article on rest parameter only has function parameter examples and it links to the function definition part of the specs. The only instance I can find of the words "rest parameter" in the specs is under the Parameter Lists section.

MDN calls it a rest property when ...rest is used with a destructuring assignment.

The specs do seem to have two versions of it if I read it correctly, the AssignmentRestElement used with arrays and the AssignmentRestProperty used with objects.

13.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation

ObjectAssignmentPattern : { AssignmentPropertyList , AssignmentRestProperty }

ArrayAssignmentPattern : [ AssignmentElementList , Elision AssignmentRestElement ]

While "rest element" might be more correct with an array I don't think using "rest property" for both arrays and objects as MDN does is the end of the world.

Affected Page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements

Your code

const [one, two, ...restElement] = [1, 2, 3, 4, 5];

const { name, age, ...restProperty } = {
  name: 'John',
  age: 30,
  email: 'example@john.com',
  address: 'Sesame Street',
};

Expected behavior

The correct technical definition should be used.

Screenshots

No response

System

  • Device: [e.g. iPhone 6, Laptop]
  • OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 22]

Additional context

This PR #35496 changed it from rest operator to rest parameter.

@lasjorg lasjorg added type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc. scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. labels Sep 8, 2022
@lasjorg
Copy link
Contributor Author

lasjorg commented Sep 8, 2022

Just so I don't forget if it is changed the hint guide needs to be updated as well.
https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements/301218

@naomi-lgbt
Copy link
Member

I'm honestly tempted to just change this to spread operator.

@lasjorg
Copy link
Contributor Author

lasjorg commented Sep 9, 2022

I assume you mean rest and not spread? Because in the context of the challenge it is rest.

The least specific verbiage would be "rest syntax", which would cover "rest parameter", "rest property", and "rest element".

I'm also not convinced ... is an operator even though it is often called it.


Even though I came to the conclusion independently by reading the specs that it is a "rest element" I now have more confidence that it is in fact the correct term (rest element).

https://2ality.com/2022/05/rest-vs-spread.html

Rest syntax:

Rest parameters
Destructuring via rest elements
Destructuring via rest properties

Spreading:

Spreading into function calls
Spreading into Array literals
Spreading into object literals

@santifoo
Copy link
Contributor

santifoo commented Sep 9, 2022

I agree that the wording isn't correct.

Spread syntax looks exactly like rest syntax. In a way, spread syntax is the opposite of rest syntax. Spread syntax "expands" an array into its elements, while rest syntax collects multiple elements and "condenses" them into a single element.

MDN

And so in that case, where it is collecting the rest of the array, it is certainly rest. And it is not an operator because it does not operate on array, as spread does.

In that case, If you use it in the right side, would become spread though XD

Rest property sounds good to me.

@lasjorg
Copy link
Contributor Author

lasjorg commented Sep 9, 2022

I just noticed that the challenge already calls it a "rest element"

The rest element only works correctly as the last variable in the list.


Here is a suggested change, I only changed the title and changed "rest parameter" to "rest syntax".

Destructuring via rest elements

In some situations involving array destructuring, we might want to collect the rest of the elements into a separate array.

The result is similar to Array.prototype.slice(), as shown below:

const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
console.log(a, b);
console.log(arr);
The console would display the values 1, 2 and [3, 4, 5, 7].

Variables a and b take the first and second values from the array. After that, because of the rest syntax presence, arr gets the rest of the values in the form of an array. The rest element only works correctly as the last variable in the list. As in, you cannot use the rest syntax to catch a subarray that leaves out the last element of the original array.

Use destructuring assignment with the rest syntax to perform an effective Array.prototype.slice() so that arr is a sub-array of the original array source with the first two elements omitted.

@moT01 moT01 added status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. and removed status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. labels Sep 21, 2022
@moT01 moT01 added first timers only Open for anyone doing contributions for first time. You do not need permission to work on these. and removed status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. labels Dec 7, 2022
@moT01
Copy link
Member

moT01 commented Dec 7, 2022

I added the first timers label. Lets go with @lasjorg's suggestion in the comment above this.

Here is a suggested change, I only changed the title and changed "rest parameter" to "rest syntax".

@rahulchopra-dev
Copy link

Hi there, I am completely new to the open source culture and i would want to make this contribution.
Am i allowed to do this contribution?
If yes, then if you guys could guide me through the process. That would be very helpful.

@Nirajn2311
Copy link
Member

Nirajn2311 commented Dec 18, 2022

An issue with the help wanted or first timers only label is open for contribution. The first comprehensive PR created will be reviewed and merged.

If have not read the contributors docs then I would suggest reading that first

If you have any issues with contributing, be sure to join us on the contributors channel, or on the contributors sub-forum

@rahulchopra-dev
Copy link

Since @roygav has already committed changes, i can't commit these changes right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first timers only Open for anyone doing contributions for first time. You do not need permission to work on these. scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants