-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex5.js
More file actions
33 lines (24 loc) · 655 Bytes
/
ex5.js
File metadata and controls
33 lines (24 loc) · 655 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';
/*
Problem:
Implement `simulateABA()`.
Goal:
- Deterministically simulate A -> B -> A transition.
- Detect that intermediate change occurred using version tagging.
- Return true when ABA occurred, false otherwise.
Starter code is intentionally incorrect:
- It checks only final value equality and misses ABA.
*/
function simulateABA() {
const slot = { value: 'A' };
const observed = slot.value;
// Another actor mutates A -> B -> A.
slot.value = 'B';
slot.value = 'A';
// Wrong: value-only check says "unchanged".
if (slot.value === observed) {
return false;
}
return true;
}
module.exports = { simulateABA };