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
| package main | |
| func main() { | |
| println("Hello, darkness my old friend") | |
| } |
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
| package main | |
| import ( | |
| "strconv" | |
| "sync" | |
| ) | |
| func main() { | |
| channel := make(chan string, 20) | |
| wg := sync.WaitGroup{} |
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
| const fs = require('fs'); | |
| const virusChecker = require('virus-checker') // some non-existing pseudo library | |
| const getFilesForProcessing = function* () { | |
| const dir = 'path/to/directory/'; | |
| const fileNames = fs.readdirSync(dir); | |
| for(const fileName of fileNames){ | |
| yield fs.readdirSync(dir + fileName); | |
| } |
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
| for(const superHero of superHeroes()){ | |
| console.log(superHero); | |
| /* | |
| Nick Fury | |
| Stephen Strange | |
| Thor Odinson | |
| Clint Barton | |
| Bruce Banner | |
| Steve Rogers | |
| Tony Stark |
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
| const superHeroes = function* () { | |
| for(let node = head; node !== null; node = node.next) { | |
| yield node.name; | |
| } | |
| } |
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
| const spiderMan = {name: "Peter Parker", next: null}; | |
| const ironMan = {name: "Tony Stark", next: spiderMan}; | |
| const captainAmerica = {name: "Steve Rogers", next: ironMan}; | |
| const hulk = {name: "Bruce Banner", next: captainAmerica}; | |
| const hawkEye = {name: "Clint Barton", next: hulk}; | |
| const thor = {name: "Thor Odinson", next: hawkEye}; | |
| const drStrang = {name: "Stephen Strange", next: thor}; | |
| const head = {name: "Nick Fury", next: drStrang}; |
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
| for(const i of inOrder(fifty)) { | |
| console.log(i); // 9 12 14 17 19 23 50 72 54 67 76 | |
| } |
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* inOrder (node) { | |
| if(node.left){ | |
| yield *inOrder(node.left); | |
| } | |
| yield node.value; | |
| if(node.right){ | |
| yield *inOrder(node.right); | |
| } | |
| } |
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
| // 9, 12, 14, 17, 19, 23, 50, 72, 54, 67, 76 | |
| const nine = {value: 9, left: null, right: null}; | |
| const fourteen = {value: 14, left: null, right: null}; | |
| const twelve = {value: 12, left: nine, right: fourteen}; | |
| const nineteen = {value: 19, left: null, right: null}; | |
| const twentythree = {value: 23, left: nineteen, right: null}; | |
| const seventeen = {value: 17, left: twelve, right: nineteen}; | |
| const sixtyseven = {value: 67, left: null, right: null}; | |
| const fiftyfour = {value: 54, left: null, right: sixtyseven}; |
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* colors() { | |
| const colors = ['red', 'blue', 'green']; | |
| for(let i = 0; ; i = (i+1) % 3) { | |
| yield colors[i]; | |
| } | |
| } |