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

Suggestion. Task for 'Iterables' article #2206

Open
nat-k-dev opened this issue Oct 15, 2020 · 2 comments
Open

Suggestion. Task for 'Iterables' article #2206

nat-k-dev opened this issue Oct 15, 2020 · 2 comments

Comments

@nat-k-dev
Copy link

It would be useful to have some practice tasks with realization of concepts in article Iterables.

An idea of task is in the article: "make an iterable object that generates an infinite sequence of pseudorandom numbers".

Possible solution:

let randomObj = {
  min: 10,
  max: 100,
}

randomObj[Symbol.iterator] = function() {
  return {
    start: this.min,
    end: this.max,
    next() {
      return {
        done: false, 
        value: Math.random() * (this.end - this.start) + this.start,
      };
    }
  }
}

const THRESHOLD = 20;

for (let value of randomObj) {
  alert(value); // show random generated value
  if (value < THRESHOLD) break;
}
@iliakan
Copy link
Member

iliakan commented Dec 5, 2020

Maybe something more practical? Not sure a task is really needed there. People rarely make iterables manually.

@iliakan
Copy link
Member

iliakan commented Dec 5, 2020

We can add something simple and potentialy useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants