Skip to content

Instantly share code, notes, and snippets.

@atg
Created October 29, 2016 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atg/77f2e3187da54a515a067bb148549a56 to your computer and use it in GitHub Desktop.
Save atg/77f2e3187da54a515a067bb148549a56 to your computer and use it in GitHub Desktop.
(function () {
var array1, array2, array3, array4, gen, y, x;
array1 = [50, 30, 70, 20];
var obj = {
idx: 0,
next: function() {
if (obj.idx >= array1.length) {
return { done: true };
}
else {
var i = obj.idx++;
return { done: false, value: array1[i] };
}
},
};
var gen = () => ({
[Symbol.iterator]: () => obj,
});
array2 = [];
array3 = [];
array4 = [];
y = gen();
for (x of y) {
array2.push(x);
if (x === 30) {
break;
}
}
for (x of y) {
array3.push(x);
}
for (x of y) {
array4.push(x);
}
console.log(array2, [50, 30]);
console.log(array3, [70, 20]);
return console.log(array4, []);
})()
@reistemhoff
Copy link

s=k log w

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment