-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes_application.js
71 lines (71 loc) · 1.5 KB
/
notes_application.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
62
63
64
65
66
67
68
69
70
71
class Note {
constructor(author, text) {
this.author = author;
this.text = text;
}
}
class NoteApplication {
constructor() {
this.notes = [];
}
create(note_content) {
if (note_content instanceof Note) {
this.notes.push(note_content);
return this.notes;
}
}
listNotes() {
if (this.notes.length > 0) {
var contents = "";
for (var i = 0; i < this.notes.length; i++){
contents += "Note ID: "+ i +"\n"+this.notes[i]['text']+"\nBy Author "+this.notes[i]['author']+"\n\n";
}
return contents;
}
return "No Notes found";
}
get(note_id) {
if (typeof(note_id) == "number") {
if (this.notes.length > note_id) {
return this.notes[note_id]['text'];
}else{
return "Invalid note id";
}
}else {
return "Enter a valid number";
}
}
search(search_text) {
var found = "";
for (var i = 0; i < this.notes.length; i++) {
if(this.notes[i].text.indexOf(search_text) > -1) {
found += "\nNote ID: "+ i +"\n"+this.notes[i].text+"\nBy Author "+this.notes[i].author+"\n";
}
}
if (found.length > 0) {
return found;
}
else {
return "word not found";
}
}
delete(note_id) {
if (typeof(note_id) == "number") {
if (this.notes.length > note_id) {
this.notes.pop(note_id);
}
console.log("delete");
}else {
return "Enter a valid number";
}
}
edit(note_id, new_content) {
if (typeof(note_id) == "number") {
if (this.notes.length >= note_id) {
this.notes[note_id] = new_content;
}
}else {
return "Enter a valid number";
}
}
}