Initial commit

This commit is contained in:
Brooke Vibber 2025-12-13 10:37:19 -08:00
commit 5eb60db655
7 changed files with 171 additions and 0 deletions

51
range.js Normal file
View file

@ -0,0 +1,51 @@
export function *rangeGenerator(max) {
for (let i = 0; i < max; i++) {
yield i;
}
}
function rangeObjectPropertyNext() {
if (this.value < this.max) {
return {
value: this.value++
}
}
return {
done: true
}
}
function rangeObjectPropertyIterator() {
return {
value: 0,
max: this.max,
next: rangeObjectPropertyNext
};
}
export function rangeObjectProperty(max) {
return {
max,
[Symbol.iterator]: rangeObjectPropertyIterator
};
}
export function rangeClosure(max) {
let value = 0;
return {
[Symbol.iterator]() {
return {
next() {
if (value < max) {
return {
value: value++
};
}
return {
done: true
};
}
};
}
};
}