From 24935d434199b97a0e75dd369b4d15f9936d4dc0 Mon Sep 17 00:00:00 2001 From: Lodisy Date: Tue, 29 Apr 2025 18:58:42 -0500 Subject: [PATCH 1/2] added funcions --- project-task.js | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/project-task.js b/project-task.js index 5cdc359..5791c52 100644 --- a/project-task.js +++ b/project-task.js @@ -19,28 +19,32 @@ 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: @@ -48,9 +52,8 @@ const todos = [ 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: @@ -58,9 +61,8 @@ const todos = [ 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: @@ -68,14 +70,12 @@ const todos = [ 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:", ...); - \ No newline at end of file + +// ============================================ +// ๐Ÿงช Console Test Your Work +// ============================================ + +// console.log("Incomplete Tasks:", ...); +// console.log("Sorted by Priority:", ...); +// console.log("All Tasks Completed:", ...); +// console.log("Sorted Incomplete Tasks:", ...); From e130c618915c318785fcb86a0fd5d6a488500d5f Mon Sep 17 00:00:00 2001 From: Lodisy Date: Wed, 30 Apr 2025 08:37:00 -0500 Subject: [PATCH 2/2] finsishedTasks --- project-task.js | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/project-task.js b/project-task.js index 5791c52..f2e0f83 100644 --- a/project-task.js +++ b/project-task.js @@ -53,24 +53,40 @@ console.log(incompleteTasks); 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. - */ +let sortedTasks = todo.sort((a, b) => { + return a.priority - b.priority; +}); +console.log(sortedTasks); -/* - ๐Ÿ”น 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. - */ +// // +// ๐Ÿ”น 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 // ============================================