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

Define an algorithm to create a Set from a List #659

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,16 @@ unordered one, since interoperability requires that any developer-exposed enumer
contents be consistent between browsers. In those cases where order is not important, we still use
ordered sets; implementations can optimize based on the fact that the order is not observable.

<div algorithm>
<p>To <dfn export for=set>create</dfn> a [=/set=], given a [=/list=] |input|:

<ol>
<li><p>Let |result| be an empty [=/set=].
<li><p>[=list/For each=] |item| of |input|, [=set/append=] |item| to |result|.
<li><p>Return |result|.
</ol>
</div>

<p>To <dfn export for=set>append</dfn> to an <a>ordered set</a>: if the set <a for=list>contains</a>
the given <a for=set>item</a>, then do nothing; otherwise, perform the normal <a>list</a>
<a for=list>append</a> operation.
Expand Down