Skip to content

Commit bba37fd

Browse files
Improve deleteCompleted loop implementation
1 parent 9a7527c commit bba37fd

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎Sprint-3/todo-list/todos.mjs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
// In `todos.mjs`, implement a function `deleteCompleted(todoList)` that removes all completed
1212
// ToDos from the given list.
1313
export function deleteCompleted(todos) {
14-
for (let i = 0; i < todos.length; i++) {
14+
for (let i = todos.length - 1; i >= 0; i--) {
1515
if (todos[i].completed === true) {
1616
todos.splice(i, 1);
17-
i--;
1817
}
1918
}
2019
}

0 commit comments

Comments
 (0)