-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (30 loc) · 859 Bytes
/
index.js
File metadata and controls
40 lines (30 loc) · 859 Bytes
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
const todos = [
`Ngopi sampe pagi`,
`Ngakak sambil jingkrak`,
`Ngoding XOXO`,
`Ngemil nasi`
];
const show = () => {
const showTodos = data => {
for (let index = 0; index < data.length; index++) {
const item = data[index];
console.log(`[${index + 1}] ${item}`);
}
};
const searchTodos = (data, textToSearch) => {
let newTodos = [];
for (let index = 0; index < data.length; index++) {
const item = data[index];
const lowerCasedItem = item.toLowerCase();
const lowerCasedText = textToSearch.toLowerCase();
if (lowerCasedItem.includes(lowerCasedText)) {
newTodos.push(item);
}
}
return newTodos;
};
showTodos(todos);
const textInput = prompt("What todo do you want to search?");
const foundTodos = searchTodos(todos, textInput);
showTodos(foundTodos);
};