Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 62 additions & 46 deletions project-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,79 @@ This activity helps build a dynamic "To-Do List Filter" based on different crite
// ============================================

const todos = [
{ task: "Wash the dishes", completed: false, priority: 3 },
{ task: "Write a blog post", completed: true, priority: 1 },
{ task: "Buy groceries", completed: false, priority: 2 },
{ task: "Study JavaScript", completed: true, priority: 1 },
{ task: "Walk the dog", completed: false, priority: 2 },
];
// ============================================
// 🔍 Tasks
// ============================================
/*
{ task: "Wash the dishes", completed: false, priority: 3 },
{ task: "Write a blog post", completed: true, priority: 1 },
{ task: "Buy groceries", completed: false, priority: 2 },
{ task: "Study JavaScript", completed: true, priority: 1 },
{ task: "Walk the dog", completed: false, priority: 2 },
];

// ============================================
// 🔍 Tasks
// ============================================

/*
🔹 Task 1: Filter Incomplete Tasks

Step-by-Step:
1. Use the `filter()` method on the todos array.

2. Use an anonymous function as the callback.
3. Return only the tasks that are not completed.
*/


/*
let incompleteTasks = todos.filter((todo) => {
return todo.completed == false;
});
console.log(incompleteTasks);

/*
🔹 Task 2: Sort Tasks by Priority

Step-by-Step:
1. Use the `sort()` method on the todos array.
2. Use an anonymous function as the comparison function.
3. Sort tasks in ascending order of priority (1 = highest).
*/


/*
🔹 Task 3: Mark All Tasks as Completed

Step-by-Step:
1. Use the `map()` method to return a new array.
2. Use an anonymous function to modify each object.
3. Change the `completed` property to `true` for every task.
*/


/*
🔹 Task 4: Combine Filters

Step-by-Step:
1. First, filter the todos to get only incomplete tasks.
2. Then, sort the filtered results by priority using `sort()`.
3. Use method chaining to perform both steps together.
*/


// ============================================
// 🧪 Console Test Your Work
// ============================================

// console.log("Incomplete Tasks:", ...);
// console.log("Sorted by Priority:", ...);
// console.log("All Tasks Completed:", ...);
// console.log("Sorted Incomplete Tasks:", ...);


let sortedTasks = todo.sort((a, b) => {
return a.priority - b.priority;
});
console.log(sortedTasks);

// //
// 🔹 Task 3: Mark All Tasks as Completed

// Step-by-Step:
// 1. Use the `map()` method to return a new array.
// 2. Use an anonymous function to modify each object.
// 3. Change the `completed` property to `true` for every task.
// */
let completedTasks = todos.map((todo) => {
return (todo.completed = true);
});
console.log(completedTasks);
// /*
// 🔹 Task 4: Combine Filters

// Step-by-Step:
// 1. First, filter the todos to get only incomplete tasks.
// 2. Then, sort the filtered results by priority using `sort()`.
// 3. Use method chaining to perform both steps together.
// */

let sortedIncompleteTasks = todos
.filter((todos) => {
return todos.completed == false;
})
.sort((a, b) => {
return a.priority - b.priority;
});
console.log(sortedIncompleteTasks);
// ============================================
// 🧪 Console Test Your Work
// ============================================

// console.log("Incomplete Tasks:", ...);
// console.log("Sorted by Priority:", ...);
// console.log("All Tasks Completed:", ...);
// console.log("Sorted Incomplete Tasks:", ...);