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

Reference for stage 3 set-methods #28414

Merged
merged 5 commits into from
Nov 9, 2023
Merged

Reference for stage 3 set-methods #28414

merged 5 commits into from
Nov 9, 2023

Conversation

Josh-Cena
Copy link
Member

Description

Adds reference for https://github.com/tc39/proposal-set-methods.

See also mdn/browser-compat-data#20479 for which browsers support it (currently Safari TP and FF nightly).

Motivation

Additional details

Related issues and pull requests

@Josh-Cena Josh-Cena requested a review from a team as a code owner August 5, 2023 15:09
@Josh-Cena Josh-Cena requested review from teoli2003 and removed request for a team August 5, 2023 15:09
@github-actions github-actions bot added the Content:JS JavaScript docs label Aug 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

Preview URLs (8 pages)
External URLs (7)

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference
Title: Set.prototype.symmetricDifference()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
Title: Set.prototype.intersection()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf
Title: Set.prototype.isSubsetOf()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union
Title: Set.prototype.union()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf
Title: Set.prototype.isSupersetOf()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference
Title: Set.prototype.difference()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom
Title: Set.prototype.isDisjointFrom()

(comment last updated: 2023-09-30 03:11:38)

Copy link
Contributor

@zloirock zloirock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add links to core-js polyfills of those methods -)

@Josh-Cena
Copy link
Member Author

Sorry, I thought I did 😄

@hamishwillee
Copy link
Collaborator

hamishwillee commented Aug 6, 2023

Is someone taking on the compatibility data for this? I can do it if needed, but not going to to so if already in hand.

@Josh-Cena
Copy link
Member Author

Already here: mdn/browser-compat-data#20479

@Josh-Cena Josh-Cena mentioned this pull request Aug 23, 2023
18 tasks
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review.


In mathematical notation, _difference_ is defined as:

<math display="block"><semantics><mrow><mi>A</mi><mo>∖</mo><mi>B</mi><mo>=</mo><mo stretchy="false">{</mo><mi>x</mi><mo>∊</mo><mi>A</mi><mo>∣</mo><mi>x</mi><mo>∉</mo><mi>B</mi><mo stretchy="false">}</mo></mrow><annotation encoding="TeX">A\setminus B = \{x\in A\mid x\notin B\}</annotation></semantics></math>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <mo>∊</mo> and <mo>∉</mo> are very different sizes. Just want to confirm that that is OK.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's mostly a font issue. MDN doesn't seem to be using a decent math font.


`difference()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`:

- If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`.
- If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its {{jsxref("Set.prototype.keys()", "keys()")}} method, and constructs a new set with all elements in `this` that are not seen in `other`.

or /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keys() method here is an arbitrary method that the user provides, which may or may not be Set.prototype.keys(). This is explained in the "set-like objects" section, linked above.

@@ -88,14 +165,28 @@ These properties are defined on `Set.prototype` and shared by all `Set` instance
- : Removes all elements from the `Set` object.
- {{jsxref("Set.prototype.delete()")}}
- : Removes the element associated to the `value` and returns a boolean asserting whether an element was successfully removed or not. `Set.prototype.has(value)` will return `false` afterwards.
- {{jsxref("Set.prototype.difference()")}}
- : Takes a set and returns a new set containing elements in this set but not in the given set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : Takes a set and returns a new set containing elements in this set but not in the given set.
- : Takes a set and returns a new set containing elements in this set that are not in the given set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find both equally fine, but the preposition "but" makes the logical relationship slightly more saliant.

@Josh-Cena Josh-Cena requested a review from estelle September 30, 2023 03:08
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally missed this. Sorry. This wasn't in my notifications.

@estelle estelle merged commit eccf9de into mdn:main Nov 9, 2023
@Josh-Cena Josh-Cena deleted the set-methods branch November 9, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants