Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // Primer ejemplo de uso de generadores
  2. function * shopping() {
  3. // stuff on the sidewalk
  4. // walking down the sidewalk
  5. // go into the store with cash
  6. const stuffFromStore = yield 'cash';
  7. // walking back home
  8. return stuffFromStore
  9. }
  10.  
  11. const gen = shopping();
  12. gen.next() // leaving our house, salimos de casa, no pasa nada
  13. // porque llegamos hasta el tercer paso
  14. // walked into the store
  15. // walking up and down the aisles...
  16. // purchase our stuff
  17. gen.next('groceries') // leaving the store with groceries
  18. gen.next()
  19. gen.next('car')
  20.  
  21. // > ------------------------------------- segundo ejercicio con departamentos
  22. const testingTeam = {
  23. lead: 'Amanda',
  24. tester: 'Bill'
  25. };
  26.  
  27. const engineeringTeam = {
  28. testingTeam,
  29. size: 3,
  30. deparment: 'Engineering',
  31. lead: 'Jill',
  32. manager: 'Alex',
  33. ingineer: 'Dave'
  34. };
  35.  
  36. function * TeamIterator(team) {
  37. yield team.lead;
  38. yield team.manager;
  39. yield team.ingineer;
  40. }
  41.  
  42. function * TestingTeamIterator(team) {
  43. yield team.lead;
  44. yield team.tester;
  45. }
  46.  
  47. const names = []
  48.  
  49. for(let name of TeamIterator(engineeringTeam)) {
  50. names.push(name);
  51. }
  52.  
  53. names
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement