diff --git a/project-task.js b/project-task.js index 5cdc359..f2e0f83 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,34 +52,46 @@ 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: - 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:", ...); - \ No newline at end of file + +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:", ...);