Skip to the content.

Next and previous state generator.

state explanation:

Example we are having state definition: 3 2 6 8 30 0 1 15 9

if current state is 0 0 0 0 0 0 0 0 0 next state from current state wil be 1 0 0 0 0 0 0 0 0

if current state is 0 0 0 0 0 0 0 0 0 previous state will be 2 1 5 7 29 1 1 14 8

if current state is 2 0 0 0 0 0 0 0 0 next state will be 0 1 0 0 0 0 0 0

if current state is 2 0 0 0 0 0 0 0 0 previous state will be 1 0 0 0 0 0 0 0

code examples

next state

const stateInitializer = [3, 2, 6, 8, 30, 0, 1, 15, 9];
const currentState = [0, 0, 0, 0, 0, 0, 0, 0, 0];
const result = stateGenerator(stateInitializer, currentState, 1);
// result [1, 0, 0, 0, 0, 0, 0, 0, 0]
const stateInitializer = [3, 2, 6, 8, 30, 0, 1, 15, 9];
const currentState = [2, 1, 5, 7, 29, 0, 0, 14, 8];
const result = stateGenerator(stateInitializer, currentState, 1);
// result [0, 0, 0, 0, 0, 0, 0, 0, 0]

previous state

const stateInitializer = [3, 2, 6, 8, 30, 0, 1, 15, 9];
const currentState = [0, 0, 0, 0, 0, 0, 0, 0, 0];
const result = stateGenerator(stateInitializer, currentState, -1);
// result [2, 1, 5, 7, 29, 0, 0, 14, 8]
const stateInitializer = [3, 2, 6, 8, 30, 0, 1, 15, 9];
const currentState = [2, 1, 5, 7, 29, 0, 0, 14, 8];
const result = stateGenerator(stateInitializer, currentState, -1);
// result [1, 1, 5, 7, 29, 0, 0, 14, 8]