-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoDoWithArray.js
More file actions
84 lines (68 loc) · 2.03 KB
/
Copy pathtoDoWithArray.js
File metadata and controls
84 lines (68 loc) · 2.03 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
74
75
76
77
78
79
80
81
82
83
84
// Согласитесь, после чтения статьи, вам стало очевидно что для задачи с TODO вам нужен именно массив, а никак не объект?
// При чем, еще интереснее будет иметь массив объектов, например такой:
const list = [];
let idN = 1;
function addTask(name, status, priority, id = idN) {
list.push({ id, name, status, priority });
idN++;
}
function changeStatus(name, status) {
function change(item, index, array) {
if (item.name == name) {
item.status = status;
}
}
list.map(change);
}
function deleteTask(name) {
function deleteT(item, index, array) {
if (item.name == name) {
list.splice(index, 1);
}
}
list.map(deleteT);
}
function showList() {
let emptyTaskList = '-';
let toDOTitle = 'TODO:';
let ProgressTitle = 'InProgress:';
let DoneTitle = 'Done:';
let TODO = 'TODO';
let PROGRESS = 'InProgress';
let DONE = 'Done';
function showListByStatus(status, title) {
let fullTaskInfo;
let count = 0;
function getList(item, index, array) {
if (item.status == status) {
count = count + 1;
return console.log(item.name);
// return item.name; // Так можно увидеть задачу как объект
}
}
console.log('\n', title);
//
// Так можно увидеть задачу как объект
// fullTaskInfo = list.filter(getList);
// console.log(fullTaskInfo);
//
list.filter(getList);
// console.log(count); // Тестировал счетчик
if (count === 0) {
console.log(emptyTaskList);
}
}
showListByStatus(TODO, toDOTitle);
showListByStatus(PROGRESS, ProgressTitle);
showListByStatus(DONE, DoneTitle);
}
addTask('test', 'TODO', 'high');
addTask('learnJS', 'InProgress', 'high');
addTask('Arr', 'InProgress', 'critical');
addTask('Tea', 'InProgress', 'low');
changeStatus('test', 'InProgress');
changeStatus('learnJS', 'TODO');
deleteTask('Tea');
addTask('goToBed', 'TODO', 'low');
console.log(list);
showList();