forked from DigitalPhoneme/JS-Objects-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskManager.js
More file actions
73 lines (60 loc) · 3.62 KB
/
Copy pathtaskManager.js
File metadata and controls
73 lines (60 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Initial object structure
const taskManager = {
tasks: [], // Array to store task objects
// Methods will be added here
};
// Sample tasks for testing
taskManager.tasks.push({
description: "Finish project",
tags: ["work", "urgent"],
priority: 1,
status: { completed: false, date: "2025-07-29" }
});
taskManager.tasks.push({
description: "Buy groceries",
tags: ["personal", "shopping"],
priority: 2,
status: { completed: true, date: "2025-07-28" }
});
// Instructions/Tasks:
// Build a Task Manager System to manage to-do tasks. Each task is an object with description (string), tags (array of strings), priority (number: 1=high, 2=medium, 3=low), and status (object with completed boolean and date string).
// Implement the following methods:
// 1. addTask(description, tags, priority, date)
// - Takes description (string), tags (array), priority (number), and date (string).
// - Validates: description is a non-empty string, tags is an array, priority is 1, 2, or 3.
// - Creates a task object with status.completed = false and adds it to tasks array.
// - Logs confirmation (e.g., "Task 'Call client' added.").
// - Test: taskManager.addTask("Call client", ["work", "urgent"], 1, "2025-07-30");
// 2. findByTag(tag)
// - Takes a tag (string) and returns an array of task descriptions matching it (case-insensitive).
// - Use 'filter' on tasks and 'some' on tags array.
// - Use string methods 'toLowerCase' and 'includes' for matching.
// - Test: console.log(taskManager.findByTag("urgent")); // Should return ["Finish project", "Call client"]
// 3. summarizeByPriority()
// - Groups tasks by priority (1, 2, 3) using an outer loop over priority levels.
// - Inner loop filters and lists tasks per priority.
// - Truncates descriptions longer than 20 chars (use 'slice') and shows status (e.g., "1. Finish project... (Pending)").
// - Use 'filter' and 'forEach' with a 'for' loop over priorities.
// - Test: taskManager.summarizeByPriority();
// 4. getTaskReport()
// - Returns a string summarizing task status (e.g., "2 tasks pending, 1 task completed: Finish project, Buy groceries, ...").
// - Use 'reduce' to count completed/pending and 'map' with 'join' to list descriptions.
// - Test: console.log(taskManager.getTaskReport());
// Challenge Problems:
// 5. getSortedPendingTasks()
// - Returns an array of pending task descriptions, sorted by due date (ascending) then priority (high to low).
// - Use 'filter' for pending tasks, 'sort' with comparators on status.date (parse with new Date()) and priority.
// - Test: console.log(taskManager.getSortedPendingTasks()); // E.g., ["Call client", "Finish project"]
// 6. tagStats()
// - Returns an object counting tag usage by completed/pending (e.g., { work: { completed: 0, pending: 2 }, urgent: { completed: 1, pending: 1 } }).
// - Use nested loops (outer over tasks, inner over tags) with 'reduce' to tally counts.
// - Test: console.log(taskManager.tagStats());
// 7. bulkMarkComplete(tag)
// - Marks all tasks with a given tag (case-insensitive) as completed, updating status.date to current date (use new Date().toISOString().split('T')[0]).
// - Logs number of tasks updated.
// - Test: taskManager.bulkMarkComplete("urgent"); console.log(taskManager.getTaskReport());
// Original Challenge Extension:
// 8. markTaskComplete(description)
// - Finds a task by description (case-insensitive), sets status.completed to true, and updates date.
// - Test: taskManager.markTaskComplete("finish project"); console.log(taskManager.getTaskReport());
// Run tests in a browser console, Node.js, or JSFiddle to verify functionality.