Skip to content

Instantly share code, notes, and snippets.

@CornerSyrup
Last active May 26, 2023 15:59
Show Gist options
  • Save CornerSyrup/c0702987709f3fe1a085f22befbdcf73 to your computer and use it in GitHub Desktop.
Save CornerSyrup/c0702987709f3fe1a085f22befbdcf73 to your computer and use it in GitHub Desktop.
Simple automata in javascript
const path1 = () => auto1;
const path2 = () => auto2;
const auto1 = {
1: path1,
2: path2,
};
const path3 = () => auto3;
const path4 = () => auto2;
const auto2 = {
3: path3,
4: path4,
};
const path5 = () => auto3;
const path6 = () => auto1;
const auto3 = {
5: path5,
6: path6,
};
let foo = [2, 3, 5].reduce((auto, path) => auto[path](), auto1);
console.log(foo);

Diagram

flowchart LR
    auto1((Auto 1))
    auto2((Auto 2))
    auto3((Auto 3))

    auto1 -->|Path 1| auto1
    auto1 -->|Path 2| auto2
    auto2 -->|Path 4| auto2
    auto2 -->|Path 3| auto3
    auto3 -->|Path 5| auto3
    auto3 -->|Path 6| auto1
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment