Created
October 29, 2016 01:49
-
-
Save atg/83cf4e5280ec5a7262906cb8491eff80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var array1, array2, array3, array4, gen, iterator, x; | |
array1 = [50, 30, 70, 20]; | |
gen = function*() { | |
return (yield* array1); | |
}; | |
array2 = []; | |
array3 = []; | |
array4 = []; | |
iterator = gen(); | |
for (var it = iterator.next(); !it.done; it = iterator.next()) { | |
var x = it.value; | |
array2.push(x); | |
if (x === 30) { | |
break; | |
} | |
} | |
for (var it = iterator.next(); !it.done; it = iterator.next()) { | |
var x = it.value; | |
array3.push(x); | |
} | |
for (var it = iterator.next(); !it.done; it = iterator.next()) { | |
var x = it.value; | |
array4.push(x); | |
} | |
console.log(array2, [50, 30]); | |
console.log(array3, [70, 20]); | |
return console.log(array4, []); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment