Closed GrosSacASac closed 5 years ago
I imagine you're intended to assume something like
function* enumerate(it) {
let i = 0;
for (let r of it) {
yield [i++, r];
}
}
(Which isn't to say the example shouldn't be clarified, just explaining what it presumably means.)
thanks, I think the example should not use a function that only exists in Python by default.
Proposal: What if Math.seededPRNG just returned a function instead of an iterator, it could then be more polymorphic with Math.random which is also just a function and not an iterator.
const seededRandom = Math.seededPRNG({seed:0});
const normalRandom = Math.random;
// ... use normalRandom() and seededRandom() interchangeably
You get that from the .next()
function on the returned iterator.
.next()
returns {done, value}
instead of value
like Math.random
I've changed up the API a bit, dropping the generator in favor of just making it in invocable function that generates a series of values.
for(const [i,r] of enumerate(Math.seededPRNG({seed:0}))) { // do something with each value if(i >= limit) break; }
enumerate is not defined