Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active October 12, 2017 14:44
Show Gist options
  • Save yancya/beb8c131d0fc1b33fe4bfcab940c70ee to your computer and use it in GitHub Desktop.
Save yancya/beb8c131d0fc1b33fe4bfcab940c70ee to your computer and use it in GitHub Desktop.
function times(n) {
const iterator = (function* gen(n) {
let count = 0;
while (count < n) {
yield count;
count++;
}
})(n);
return Array.from(iterator);
}
times(3).forEach(()=>console.log('hoge'));
for(let i of times(3)) { console.log('hoge'); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment