Modify the scale depending on the order of the keyframe values I want to make a Dorkly animation (
                
            ), that is, 8-bit puppets opening and closing their mouths. The difference I want to add is when the mouth is open the puppet get stretched (scaled) in the Y axis and when is closed the puppet returns to its original size. I have managed to get an automatic sync method so the problem now lies with the scale thing.

I've assigned a null that responds to the values adopted by the mouth so I ordered it when the mouth is open, stretch the puppet. To do this, I've used the following expression:

x=thisComp.layer("SIDE MOUTH GREEN").effect("LJ - visemes - MSD")("viseme nr.")
if(x==1)[148,199];
else if (x==3) [148,199];
else if (x==7) [148,199];
else if (x==10) [148,199];
else if (x==11) [148,199];
else [148,189];


The problem is as follows. When there are two consecutive sounds that are equivalent to an open mouth (FOR - GO - tten), the puppet doesn't move and that's a pretty dull stuff. What should be said to AF is: if after an open mouth value goes another open mouth value, on the changed value disable the stretching for X time. What'd be the expression that would be needed to achieve that? 

I know I could do it manually but I want to broaden my skills.
To shorten what you've already written you could pack all the open mouth values into an array and then find if the x value is in it:

var scaleYVals = [1 , 3, 7, 10, 11];
(scaleYVals.indexOf(x) &gt; -1)? [148,199] : [148, 189];


The second line uses the ternary form of if (foo){bar} else {baz}, which can be written as (foo)? bar : baz. IndexOf returns the index of an element of an array, so if the value of x (bad name for a variable except if you're referring to an x coordinate, BTW) is 7 then indexOf will return 2. If the value is not in the array it returns -1

The problem with looking at the previous mouth shape is that you could still end up with no movement: say there was a sequence: open, open, closed. If you disable the stretching on the second open mouth you'll have the sequence stetched, unstretched, unstretched. It also greatly complicates the expression.

How about you make it so that the stretch happens at the beginning of the open mouth and then goes back briefly before the next phoneme?