-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.js
More file actions
48 lines (36 loc) · 1.07 KB
/
index3.js
File metadata and controls
48 lines (36 loc) · 1.07 KB
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
44
45
46
47
48
//Contoh Jawaban 1
var readBooks = require('./callback.js')
var books = [
{name: 'LOTR', timeSpent: 3000},
{name: 'Fidas', timeSpent: 2000},
{name: 'Kalkulus', timeSpent: 4000}
];
var timeAvailable = 10000;
readBooks(timeAvailable, books[0], function(time) {
readBooks(time, books[1], function(time) {
readBooks(time, books[2], function(time){
readBooks(time, books[0], function(time){
return time;
})
})
})
});
//Contoh Jawaban 2
// var readBooks = require('./callback.js')
// var books = [
// {name: 'LOTR', timeSpent: 3000},
// {name: 'Fidas', timeSpent: 2000},
// {name: 'Kalkulus', timeSpent: 4000}
// ]
// var booksQueue = books.length;
// var time = 10000;
// function execute(time, ind, booksQueue) {
// readBooks(time, books[ind], function(remainingTime) {
// time = remainingTime;
// booksQueue = booksQueue - 1;
// if (booksQueue > 0) {
// execute(time, ind+1, booksQueue);
// }
// });
// }
// execute(time, 0, booksQueue);