-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelegation.js
More file actions
43 lines (33 loc) · 816 Bytes
/
delegation.js
File metadata and controls
43 lines (33 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const ford = {
sellLeader: 'F150',
sellLeaderPrice: '39k USD'
};
const chevy = {
sellLeader: 'Silverado',
sellLeaderPrice: '38.900k USD'
};
const car = {
ford,
chevy,
nrBrands: 2,
avgPrice: '35k USD',
marketLeader: 'Ford'
};
function* CarIterator(car) {
yield `Nr Brand Leaders ${car.nrBrands}`;
yield `Avg Price: ${car.avgPrice}`;
const fordIterator = BrandIterator(car.ford);
yield* fordIterator;
const chevyIterator = BrandIterator(car.chevy);
yield* chevyIterator;
yield `Leader 2016: ${car.marketLeader}`;
}
function* BrandIterator(brand) {
yield brand.sellLeader;
yield brand.sellLeaderPrice;
}
const weirdExample = [];
for (let item of CarIterator(car)) {
weirdExample.push(item);
}
console.log(weirdExample);