keep length check dynamic as the size of ary can change during the loop
Merge pull request #1096 from clmath/fixTrimDot

Unnecessary iterations in trimDot