|
|
@@ -1,27 +1,60 @@
|
|
|
-const notes = ['Note 1', 'Note 2', 'Note 3']
|
|
|
-
|
|
|
-// console.log(notes.pop())
|
|
|
-// notes.push('My new note')
|
|
|
-
|
|
|
-// console.log(notes.shift())
|
|
|
-// notes.unshift('My first note')
|
|
|
-
|
|
|
-// notes.splice(1, 1, 'This is the new second item')
|
|
|
-
|
|
|
-notes[2] = 'This is the new note 3'
|
|
|
-
|
|
|
-notes.forEach(function (item, index) {
|
|
|
- console.log(index)
|
|
|
- console.log(item)
|
|
|
-})
|
|
|
-
|
|
|
-console.log(notes.length)
|
|
|
-console.log(notes)
|
|
|
-
|
|
|
-for (let count = 0; count <= 2; count++) {
|
|
|
- console.log(count)
|
|
|
+const notes = [{
|
|
|
+ title: 'My next trip',
|
|
|
+ body: 'I would like to go to Spain'
|
|
|
+}, {
|
|
|
+ title: 'Habits to work on',
|
|
|
+ body: 'excercise. eating a bit better'
|
|
|
+}, {
|
|
|
+ title: 'Office modifications',
|
|
|
+ body: 'Set up table'
|
|
|
+}]
|
|
|
+
|
|
|
+// const findNote = function (notes, noteTitle) {
|
|
|
+// const index = notes.findIndex(function (note, index) {
|
|
|
+// let currentTitle = String(note.title).toLowerCase()
|
|
|
+// console.log(currentTitle)
|
|
|
+// return currentTitle === noteTitle.toLowerCase()
|
|
|
+// })
|
|
|
+// return notes[index]
|
|
|
+// }
|
|
|
+
|
|
|
+const findNote = function (notes, noteTitle) {
|
|
|
+ return notes.find(function (note, index) {
|
|
|
+ let currentTitle = String(note.title).toLowerCase()
|
|
|
+ console.log(currentTitle)
|
|
|
+ return currentTitle === noteTitle.toLowerCase()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-for (let count = 0; count < notes.length; count++) {
|
|
|
- console.log(notes[count])
|
|
|
-}
|
|
|
+const findNotes = function (notes, query){
|
|
|
+ return notes.filter(function (note, index) {
|
|
|
+ const isTitleMatch = note.title.toLowerCase().includes(query.toLowerCase())
|
|
|
+ const isBodyMatch = note.body.toLowerCase().includes(query.toLowerCase())
|
|
|
+ // const isTitleMatch = String(note.title).toLowerCase().includes('ne')
|
|
|
+ // const isBodyMatch = String(note.body).toLowerCase().includes('ne')
|
|
|
+ return isTitleMatch || isBodyMatch
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+console.log(findNotes(notes, 'eating'))
|
|
|
+
|
|
|
+// const note = findNote(notes, 'office other modifications')
|
|
|
+// console.log(note)
|
|
|
+// console.log(notes.length)
|
|
|
+// console.log(notes)
|
|
|
+
|
|
|
+// for (let count = 0; count <= 2; count++) {
|
|
|
+// console.log(count)
|
|
|
+// }
|
|
|
+
|
|
|
+// for (let count = 0; count < notes.length; count++) {
|
|
|
+// console.log(notes[count])
|
|
|
+// }
|
|
|
+
|
|
|
+// const index = notes.findIndex(function (note, index) {
|
|
|
+// console.log(note)
|
|
|
+// return note.title === 'Habits to work on'
|
|
|
+// })
|
|
|
+
|
|
|
+// console.log(index)
|