A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,36 @@
|
|||
function PowersGenerator(m) {
|
||||
var n=0;
|
||||
while(1) {
|
||||
yield Math.pow(n, m);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
|
||||
function FilteredGenerator(g, f){
|
||||
var value = g.next();
|
||||
var filter = f.next();
|
||||
|
||||
while(1) {
|
||||
if( value < filter ) {
|
||||
yield value;
|
||||
value = g.next();
|
||||
} else if ( value > filter ) {
|
||||
filter = f.next();
|
||||
} else {
|
||||
value = g.next();
|
||||
filter = f.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var squares = PowersGenerator(2);
|
||||
var cubes = PowersGenerator(3);
|
||||
|
||||
var filtered = FilteredGenerator(squares, cubes);
|
||||
|
||||
|
||||
|
||||
for( var x = 0; x < 20; x++ ) filtered.next()
|
||||
for( var x = 20; x < 30; x++ ) console.logfiltered.next());
|
||||
Loading…
Add table
Add a link
Reference in a new issue