Don't use `i` here.  Shouldn't it be `i - 1` anyway?  Regardless, use `length` because the semantics are much better.