0

What is your method of dealing with states in state machines? In programming, we often come across situations where we have to model states in our head as to not get the programming wrong, e.g. in my case right now:

You have a tabular webform that gets filled in.
Requirements:
- When the user is able to search the data for a specific value, it should be a cumulative search (e.g.: search for books with "eng" in the language and then with with "19" in the publishing date)

And so the current pseudocode is:
search(e) {
if(!word) {
set(previousState);
}
const searchdata = previousState.filter((row) => row.indexOf(word) != -1);
// but wait, what if I say: searchdata = searchdata.filter() for cumulative search? Oops, I can't, because it doesn't exist at that moment yet. What if I create another variable?

setState(data: searchdata);
}

Current bug:
- when deleting characters from the search field, it doesn't filter cumulatively; it just filters the data according to the current filter.

It's things like these that get me stuck sometimes.

Comments
Add Comment