Created
October 3, 2026 07:07
-
-
Save thinkphp/320f1683f962dd14d3117e108f20d152 to your computer and use it in GitHub Desktop.
generator-intrebare interview.
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* generator( i ) { | |
| yield i; | |
| yield i * 2; | |
| yield i * i * 2; | |
| } | |
| const gen = generator( 10 ); | |
| console.log(gen.next().value); | |
| console.log(gen.next().value); | |
| console.log(gen.next().value); | |
| /* | |
| Codul se executa pas cu pas, pentru ca un generator nu ruleaza tot corpul functiei de la inceput, ci doar pana la urmatorul yield, | |
| de fiecare data cand apelezi gen.next | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment