-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path2-reject.js
More file actions
33 lines (29 loc) · 688 Bytes
/
2-reject.js
File metadata and controls
33 lines (29 loc) · 688 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
'use strict';
// Task: support rejection with an error after last item
const iterate = (items) => {
let index = 0;
return {
then(fulfill /*reject*/) {
// Call both: fulfill and reject
if (index < items.length) {
fulfill(items[index++]);
}
},
};
};
const electronics = [
{ name: 'Laptop', price: 1500 },
{ name: 'Keyboard', price: 100 },
{ name: 'HDMI cable', price: 10 },
];
(async () => {
const items = iterate(electronics);
const item1 = await items;
console.log(item1);
const item2 = await items;
console.log(item2);
const item3 = await items;
console.log(item3);
const item4 = await items;
console.log(item4);
})();