From c411a60661b7750836d6b8abdc375193381bfff9 Mon Sep 17 00:00:00 2001 From: Nik Bezdzenariy Date: Thu, 30 Apr 2026 13:18:27 +0200 Subject: [PATCH 1/4] feat: add deleteCompleted function Implement deleteCompleted() in todos.mjs to remove all completed tasks from the todos array using filter and in-place splice mutation. --- Sprint-3/todo-list/todos.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..0461100ed 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -26,4 +26,9 @@ export function toggleCompletedOnTask(todos, taskIndex) { if (todos[taskIndex]) { todos[taskIndex].completed = !todos[taskIndex].completed; } +} + +export function deleteCompleted(todos) { + const remaining = todos.filter(todo => !todo.completed); + todos.splice(0, todos.length, ...remaining); } \ No newline at end of file From f92e991126723fb73e200e70238caf3f2a23d90c Mon Sep 17 00:00:00 2001 From: Nik Bezdzenariy Date: Thu, 30 Apr 2026 13:18:43 +0200 Subject: [PATCH 2/4] test: add unit tests for deleteCompleted Add 3 test cases: - Delete all completed tasks from mixed list - Do nothing when no tasks are completed - Empty list when all tasks are completed --- Sprint-3/todo-list/todos.test.mjs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-3/todo-list/todos.test.mjs b/Sprint-3/todo-list/todos.test.mjs index d6bf96414..d596d6703 100644 --- a/Sprint-3/todo-list/todos.test.mjs +++ b/Sprint-3/todo-list/todos.test.mjs @@ -130,3 +130,30 @@ describe("toggleCompletedOnTask()", () => { }); }); +describe("deleteCompleted()", () => { + test("Delete all completed tasks", () => { + const todos = createMockTodos(); + Todos.deleteCompleted(todos); + expect(todos).toHaveLength(2); + expect(todos[0].task).toEqual("Task 2 description"); + expect(todos[1].task).toEqual("Task 4 description"); + }); + + test("Does nothing when no task are completed", () => { + const todos = [ + {task: "A", completed: false}, + {task: "B", completed: false}, + ]; + Todos.deleteCompleted(todos); + expect(todos).toHaveLength(2); + }); + + test("Empties the list when all tasks are completed", () => { + const todos = [ + {task: "A", completed: true}, + {task: "B", completed: true}, + ]; + Todos.deleteCompleted(todos); + expect(todos).toHaveLength(0); + }); +}); \ No newline at end of file From 2150d0936899771379ce172f3ce8ce0a325353c2 Mon Sep 17 00:00:00 2001 From: Nik Bezdzenariy Date: Thu, 30 Apr 2026 13:19:01 +0200 Subject: [PATCH 3/4] feat: add 'Delete completed tasks' button Add button element with id 'delete-completed-btn' after the todo list to trigger mass deletion of completed tasks. --- Sprint-3/todo-list/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..8178f455c 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -21,6 +21,8 @@

My ToDo List

+ +