Skip to content

Commit 0fe1d22

Browse files
committed
update remove all completed todos todos.mjs and clean code in script.mjs
1 parent 656960c commit 0fe1d22

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

Sprint-3/todo-list/script.mjs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@ const todos = [];
77

88
// Set up tasks to be performed once on page load
99
window.addEventListener("load", () => {
10-
//get the deleted complete button from html
1110
const massDeleteBtn = document.querySelector("#delete-completed-btn");
1211

13-
// check if the button is even found in the HTML
14-
// console.log("Button found:", massDeleteBtn);
15-
1612
if (massDeleteBtn) {
1713
massDeleteBtn.addEventListener("click", () => {
18-
// check if the click event is firing
19-
// console.log("Mass delete button clicked!");
20-
// console.log("Todos before delete:", JSON.parse(JSON.stringify(todos)));
2114
Todos.deleteCompleted(todos);
22-
// check if the array actually changed
23-
// console.log("Todos after delete:", JSON.parse(JSON.stringify(todos)));
2415
render();
2516
});
2617
}
@@ -34,9 +25,8 @@ window.addEventListener("load", () => {
3425
render();
3526
});
3627

37-
38-
// A callback that reads the task description from an input field and
39-
// append a new task to the todo list.
28+
// A callback function that reads the task description from an input field and
29+
// appends a new task to the todo list.
4030
function addNewTodo() {
4131
const taskInput = document.getElementById("new-task-input");
4232
const task = taskInput.value.trim();
@@ -64,7 +54,6 @@ function render() {
6454
});
6555
}
6656

67-
6857
// Note:
6958
// - First child of #todo-item-template is a <li> element.
7059
// We will create each ToDo list item as a clone of this node.

Sprint-3/todo-list/todos.mjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,5 @@ export function toggleCompletedOnTask(todos, taskIndex) {
3030

3131
// Removes all completed ToDos from the given list
3232
export function deleteCompleted(todos) {
33-
// Loop backwards so removing items doesn't shift indexes and skip elements
34-
for (let i = todos.length - 1; i >= 0; i--) {
35-
if (todos[i].completed) {
36-
todos.splice(i, 1);
37-
}
38-
}
33+
return todos.filter((todo) => !todo.completed);
3934
}

0 commit comments

Comments
 (0)