Prefer collect over creating an array and appending in a loop.