teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

コード修正

2017/06/28 12:41

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -17,10 +17,8 @@
17
17
 
18
18
  const duplicatedNotes = notes.filter(note => note.title === title);
19
19
 
20
- if (duplicatedNotes.length > 0) {
20
+ if (duplicatedNotes.length > 0) { return null; }
21
- return null;
21
+
22
- }
23
-
24
22
  notes.push(note);
25
23
  this.saveNotes(notes);
26
24
  return note;

2

コード修正

2017/06/28 12:41

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -17,13 +17,13 @@
17
17
 
18
18
  const duplicatedNotes = notes.filter(note => note.title === title);
19
19
 
20
- if (duplicatedNotes.length === 0) {
20
+ if (duplicatedNotes.length > 0) {
21
- notes.push(note);
22
- this.saveNotes(notes);
23
- return note;
24
- } else {
25
21
  return null;
26
22
  }
23
+
24
+ notes.push(note);
25
+ this.saveNotes(notes);
26
+ return note;
27
27
  }
28
28
  ```
29
29
 

1

コード修正

2017/06/28 12:38

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -2,12 +2,8 @@
2
2
 
3
3
  ```JavaScript
4
4
  getNote(title) {
5
-
6
5
  const notes = this._fetchNotes();
7
- const filteredNotes = notes.filter((note) => {
6
+ const filteredNotes = notes.filter(note => note.title === title);
8
- return note.title === title;
9
- });
10
-
11
7
  return filteredNotes.length > 0 ? filteredNotes[0] : null;
12
8
  }
13
9
  ```
@@ -16,14 +12,11 @@
16
12
 
17
13
  ```JavaScript
18
14
  addNote(title, body) {
19
-
20
15
  let notes = this._fetchNotes();
21
16
  const note = {title, body};
22
17
 
23
- const duplicatedNotes = notes.filter((note) => {
18
+ const duplicatedNotes = notes.filter(note => note.title === title);
24
- return note.title === title;
19
+
25
- });
26
-
27
20
  if (duplicatedNotes.length === 0) {
28
21
  notes.push(note);
29
22
  this.saveNotes(notes);