CodeWitness

Refactor a filter-and-collect loop

The loop selects active users and appends each selected user’s name to a new array.

const activeNames = [];
for (const user of users) {
  if (user.active) {
    activeNames.push(user.name);
  }
}

Refactor the selection and projection into array operations while preserving order.

Which expression keeps active users and returns their names in the same order?