Length evaluation moved outside the for-loop

Standard JS best practice