Replace some for loops with array operations.