-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempCodeRunnerFile.javascript
58 lines (51 loc) · 1.36 KB
/
tempCodeRunnerFile.javascript
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
const filterByName = (items, name) => {
if (name !== undefined) {
// return items.filter((item) => item.name.toLowerCase() === name.toLowerCase());
return items.filter((item) => item.name.toLowerCase() === name.toLowerCase())
}
return items;
};
const filterByReading = (items, reading) => {
const cond = reading !== undefined && [0, 1].includes(reading);
if (cond) {
return items.filter(
(item) => Number(item.reading) === Number(reading),
);
}
return items;
};
const filterByFinished = (items, finished) => {
const cond = finished !== undefined && [0, 1].includes(finished);
if (cond) {
return items.filter(
(item) => Number(item.finished) === Number(finished),
);
}
return items;
};
const books = [
{
name: 'aku',
reading: true,
finished: false,
},
{
name: 'ksmu',
reading: true,
finished: false,
},
{
name: 'mereka',
reading: false,
finished: true,
}
];
console.log('is aku?');
console.log(filterByName(books, 'aKu'));
console.log(filterByName(books, 'zzzzz'));
console.log('is Reading?');
console.log(filterByReading(books, 1));
console.log(filterByReading(books, 3));
console.log('is finish?');
console.log(filterByFinished(books, 1));
console.log(filterByFinished(books, 0));