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
49
50
import { roundRobin } from "https://esm.town/v/thedavis/roundRobin";
export function whoNext(query, arg) {
const m = {
"help": () =>
"list/peek/rotate to view/peek/modify the schedule. add/remove with an argument also supported.",
/// Add to the end of the order.
"add": (arg) => {
roundRobin.push(arg);
return roundRobin.toString();
},
"list": () => roundRobin.toString(),
/// See who the next person is without modifying the order.
"peek": () =>
roundRobin.length === 0
? "Nobody in the round robin!"
: roundRobin[0],
/// Returns the next person in the order.
/// Then modifies the order so that person is last.
"rotate": () => {
if (roundRobin.length == 0) {
return "Nobody in the round robin!";
}
else {
let shifted = roundRobin.shift();
roundRobin.push(shifted);
return shifted;
}
},
/// Searches the order for a person to remove.
"remove": (arg) => {
const index = roundRobin.indexOf(arg);
if (index > -1) {
roundRobin.splice(index, 1);
}
},
/// Defers the person at the top of the order to the next-to-next.
/// TODO: doesnt work when the new next wants to defer as well...
"defer": (arg) => {
let deferred = roundRobin.shift();
let newNext = roundRobin.shift();
roundRobin.unshift(deferred);
roundRobin.unshift(newNext);
},
};
const v = m[query];
if (v) {
return v(arg);
}
else {