fac18 / week2-CEFG-To-do

Create a to-do app
https://fac18.github.io/week2-CEFG-To-do/
0 stars 1 forks source link

Exiting for loops with a return statement #30

Closed bobbysebolao closed 4 years ago

bobbysebolao commented 4 years ago

You have written a really nice markTodo function in logic.js. 🥇

But, if the very first todo in the array meets the if condition on line 60, the loop will continue to go through the remaining todos.

for (let item of newTodos) {
      if (item.id == idToMark) {
        item.done ? (item.done = false) : (item.done = true);
      }
    }

You can add a return statement after line 61 to make the loop exit as soon as the if condition is met 👍 this will make your code run faster, especially if the todo array is very long!