Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 499 Bytes

1-cycle-exit.md

File metadata and controls

23 lines (17 loc) · 499 Bytes

Циклы не работают дольше чем нужно, а количество их вызовов минимизировано.

Неправильно:

apartments.forEach((it, index) => {
  if (index < 3) {
    render(it);
  }
});

Правильно:

for (let i = 0; i < Math.min(apartments.length, 3); i++) {
  render(apartments[i]);
}

Почему нужно соблюдать этот критерий?

Лишняя работа?