Last active
September 7, 2018 06:36
-
-
Save cnaa97/10b4272735255e36e61b96c3ef1c8bd7 to your computer and use it in GitHub Desktop.
Multiplication Table using Javascript Generator
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
/** | |
* 코드스피츠 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