There is a misprint inside the secondary loop, it should be: if (t == BKeyTimes[i]) { (==, not =).
Additionnaly, the loop logic isnt very good: as it is now, it will remove a keyframe on A as soon as that keyframe’s time doesnt match ALL keyframes times on B, which is impossible except in rare situations (only one key on B).
You’d rather want to keep the key on A if its time matches ONE key time on B, and remove otherwise.
Here is another approach, simpler to write down, but which might be slow if many keyframes, because of the use of nearestKeyIndex:
function sameTimes(t1, t2){
return Math.abs(t2-t1)<;=0.0005;
};
function removeAllKeys(prop){
while(prop.numKeys>0) prop.removeKey(prop.numKeys);
};
function removeKeys(A, B){
if (B.numKeys===0) return removeAllKeys(A);
var idxA, idxB, tA, tB;
for (idxA=A.numKeys; idxA>0; idxA--){
tA = A.keyTime(idxA);
idxB = B.nearestKeyIndex(tB);
tB = B.keyTime(idxB);
if (!sameTimes(tA, tB)) A.removeKey(idxA);
};
};
Xavier