-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathindex.js
61 lines (55 loc) · 1.13 KB
/
index.js
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
'use strict';
// { name: タスクの名前, isDone: 完了しているかどうかの真偽値 }
const tasks = [];
/**
* タスクを追加する
* @param {string} taskName
*/
function add(taskName) {
tasks.push({ name: taskName, isDone: false });
}
/**
* タスクの一覧の配列を取得する
* @returns {string[]}
*/
function list() {
return tasks
.filter(task => !task.isDone)
.map(task => task.name);
}
/**
* タスクを完了状態にする
* @param {string} taskName
*/
function done(taskName) {
const indexFound = tasks.findIndex(task => task.name === taskName);
if (indexFound !== -1) {
tasks[indexFound].isDone = true;
}
}
/**
* 完了済みのタスクの一覧の配列を取得する
* @returns {string[]}
*/
function donelist() {
return tasks
.filter(task => task.isDone)
.map(task => task.name);
}
/**
* 項目を削除する
* @param {string} taskName
*/
function del(taskName) {
const indexFound = tasks.findIndex(task => task.name === taskName);
if (indexFound !== -1) {
tasks.splice(indexFound, 1);
}
}
module.exports = {
add,
list,
done,
donelist,
del
};