Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exiting for loops with a return statement #30

Closed
bobbysebolao opened this issue Nov 8, 2019 · 0 comments · Fixed by #37
Closed

Exiting for loops with a return statement #30

bobbysebolao opened this issue Nov 8, 2019 · 0 comments · Fixed by #37
Assignees

Comments

@bobbysebolao
Copy link

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!

@marialani marialani self-assigned this Nov 8, 2019
marialani added a commit that referenced this issue Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants