Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Primer ejemplo de uso de generadores
- function * shopping() {
- // stuff on the sidewalk
- // walking down the sidewalk
- // go into the store with cash
- const stuffFromStore = yield 'cash';
- // walking back home
- return stuffFromStore
- }
- const gen = shopping();
- gen.next() // leaving our house, salimos de casa, no pasa nada
- // porque llegamos hasta el tercer paso
- // walked into the store
- // walking up and down the aisles...
- // purchase our stuff
- gen.next('groceries') // leaving the store with groceries
- gen.next()
- gen.next('car')
- // > ------------------------------------- segundo ejercicio con departamentos
- const testingTeam = {
- lead: 'Amanda',
- tester: 'Bill'
- };
- const engineeringTeam = {
- testingTeam,
- size: 3,
- deparment: 'Engineering',
- lead: 'Jill',
- manager: 'Alex',
- ingineer: 'Dave'
- };
- function * TeamIterator(team) {
- yield team.lead;
- yield team.manager;
- yield team.ingineer;
- }
- function * TestingTeamIterator(team) {
- yield team.lead;
- yield team.tester;
- }
- const names = []
- for(let name of TeamIterator(engineeringTeam)) {
- names.push(name);
- }
- names
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement