Checking for all combinations
if ( ( s [ i ] === " " && previous_state === 0 ) || ( s [ i ] === " " && previous_state === 3 ) ) { final_state = 1 ; } else if ( ( s [ i ] === " " && previous_state === 3 ) || ( s [ i ] === " " && previous_state === 0 ) ) { final_state = 2 ; } else if ( ( s [ i ] === " " && previous_state === 1 ) || ( s [ i ] === " " && previous_state === 2 ) ) { final_state = 0 ; } else if ( ( s [ i ] === " " && previous_state === 2 ) || ( s [ i ] === " " && previous_state === 1 ) ) { final_state = 3 ; }