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

Iterator.prototype.some() example incorrectly claims a return value of false #37110

Closed
Hexstream opened this issue Dec 5, 2024 · 4 comments · Fixed by #37120
Closed

Iterator.prototype.some() example incorrectly claims a return value of false #37110

Hexstream opened this issue Dec 5, 2024 · 4 comments · Fixed by #37120
Labels
Content:JS JavaScript docs good first issue A good issue for newcomers to get started with.

Comments

@Hexstream
Copy link

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/some

What specific section or headline is this issue about?

Using some()

What information was incorrect, unhelpful, or incomplete?

// false should be // true.

What did you expect to see?

Correct return value.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

MDN metadata

Page report details
@Hexstream Hexstream added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Dec 5, 2024
@github-actions github-actions bot added the Content:JS JavaScript docs label Dec 5, 2024
@Josh-Cena
Copy link
Member

This line:

console.log(fibonacci().take(10).some(isPositive)); // false

Should be changed to:

console.log(fibonacci().take(10).some(isNegative)); // false

@Josh-Cena Josh-Cena added good first issue A good issue for newcomers to get started with. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Dec 5, 2024
@Hexstream
Copy link
Author

Hexstream commented Dec 5, 2024

It could be that, in which case we can delete const isPositive = (x) => x > 0;.

Or the line could instead be changed to:

console.log(fibonacci().some(isPositive)); // true

This is perhaps better due to better "symmetricality" of examples:

console.log(fibonacci().some(isPositive)); // true
console.log(fibonacci().some(isNegative)); // Never completes

VS

console.log(fibonacci().take(10).some(isNegative)); // false
console.log(fibonacci().some(isNegative)); // Never completes

However, in that case the isEven part becomes redundant and could be deleted.
We should still have an example of returning false from some, though...

So the full example minus the fibonacci definition could be:

const isNegative = (x) => x < 0;
const isPositive = (x) => x > 0;
console.log(fibonacci().take(10).some(isNegative)); // false
console.log(fibonacci().some(isPositive)); // true
console.log(fibonacci().some(isNegative)); // Never completes

In other words, this combines your proposed line, my proposed line and removing the now redundant isEven part.

@Josh-Cena
Copy link
Member

The goal of this example is to demonstrate what happens if nothing matches: a finite iterator returns false, while an infinite iterator never completes. The "something matches" case is already covered by the previous isEven example.

This was a simple typo of mine when I copied the Iterator.prototype.every page.

@Hexstream
Copy link
Author

Whatever works. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs good first issue A good issue for newcomers to get started with.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants