| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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()
- })
- }
- 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)
|