Skip to content

Commit 743c0b4

Browse files
committed
implement deleteCompleted()
1 parent 61ced0a commit 743c0b4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ export function toggleCompletedOnTask(todos, taskIndex) {
2626
if (todos[taskIndex]) {
2727
todos[taskIndex].completed = !todos[taskIndex].completed;
2828
}
29-
}
29+
}
30+
31+
// 2. In `todos.mjs`, implement a function `deleteCompleted(todoList)` that removes all completed
32+
// ToDos from the given list.
33+
export function deleteCompleted(todoList) {
34+
for (let i = todoList.length - 1; i >= 0; i--) {
35+
if (todoList[i].completed === true) {
36+
todoList.splice(i, 1);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)