Skip to content

Instantly share code, notes, and snippets.

@cnaa97
Last active September 7, 2018 06:36
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 cnaa97/10b4272735255e36e61b96c3ef1c8bd7 to your computer and use it in GitHub Desktop.
Save cnaa97/10b4272735255e36e61b96c3ef1c8bd7 to your computer and use it in GitHub Desktop.
Multiplication Table using Javascript Generator
/**
* 코드스피츠 3기 함수편의 2회차 과제를 제출합니다.
*
* 다음의 코드는 구구단을 출력한다.
* 이를 만족하는 제네레이터를 작성하시오.
*/
const generator = function*(i, j) {
for (let x=1; x<=i; x++) {
for (let y=1; y<=j; y++) {
yield [x, y, x * y]
}
}
};
for (const [i, j, k] of generator(9, 9)) {
console.log(`${i} x ${j} = ${k}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment