-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Comments
This line: console.log(fibonacci().take(10).some(isPositive)); // false Should be changed to: console.log(fibonacci().take(10).some(isNegative)); // false |
It could be that, in which case we can delete 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 So the full example minus the 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 |
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 This was a simple typo of mine when I copied the |
Whatever works. :) |
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
en-us/web/javascript/reference/global_objects/iterator/some
The text was updated successfully, but these errors were encountered: