change jsanimation code to use array operations