Skip to content

Instantly share code, notes, and snippets.

@hohoonlee
Created September 7, 2018 05:57
Show Gist options
  • Select an option

  • Save hohoonlee/1d4c92fb6cf4b0dfbe87d40358acfba1 to your computer and use it in GitHub Desktop.

Select an option

Save hohoonlee/1d4c92fb6cf4b0dfbe87d40358acfba1 to your computer and use it in GitHub Desktop.
const generator = function*(i, j){
for(let ii = 1; ii <= i; ii++) {
for(let jj = 1; jj <= j; jj++) {
yield [ii, jj, ii * jj];
}
}
};
for(const [i, j, k] of generator(9,9)){
console.log(`${i} x ${j} = ${k}`);
}
//1 x 1 = 1
//1 x 2 = 2
//...
//9 x 8 = 72
//9 x 9 = 81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment