-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.js
More file actions
53 lines (45 loc) · 963 Bytes
/
logic.js
File metadata and controls
53 lines (45 loc) · 963 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
44
45
46
47
48
49
50
51
52
53
const sequence = () => {
const seq = [];
let pos = 0;
const getNext = () => {
// hardcoded for now - set in config
seq.push(Math.floor(Math.random() * 4)); // exclusive of max
pos = 0;
};
// const get = () => {
// return seq;
// };
function* get() {
const values = [...seq];
while (values.length > 0) {
yield values.shift();
}
return -1;
}
const check = (val) => {
if (seq[pos] === val) {
pos++;
return {
matches: true,
remain: seq.length - pos,
input: val,
};
}
return {
matches: false,
reason: `input ${val} does not match ${seq[pos]}`,
};
};
getNext();
getNext();
return {get, getNext, check};
};
// const b = sequence();
// console.log(b.get());
// b.next();
// console.log(b.get());
// console.log(b.match(1));
// console.log(b.match(b.get()[0]));
// TODO - jest
// TODO review init point
export default sequence();