Skip to content

Commit d971640

Browse files
Updated deleCompleted function so it modifies the passed array
1 parent 30cdff5 commit d971640

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ function deleteCompletedTodos() {
4242
const newTodos = Todos.deleteCompleted(todos);
4343

4444
// Replace the old array contents
45-
todos.length = 0;
46-
todos.push(...newTodos);
45+
Todos.deleteCompleted(todos);
4746

4847
render();
4948
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export function toggleCompletedOnTask(todos, taskIndex) {
2828
todos[taskIndex].completed = !todos[taskIndex].completed;
2929
}
3030
}
31-
export function deleteCompleted(todos) {
32-
return todos.filter((todo) => !todo.completed);
31+
32+
export function deleteCompleted(todoList) {
33+
const remaining = todoList.filter((todo) => !todo.completed);
34+
todoList.length = 0;
35+
todoList.push(...remaining);
36+
37+
return todoList;
3338
}

0 commit comments

Comments
 (0)