notes.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const notes = [{
  2. title: 'My next trip',
  3. body: 'I would like to go to Spain'
  4. }, {
  5. title: 'Habits to work on',
  6. body: 'excercise. eating a bit better'
  7. }, {
  8. title: 'Office modifications',
  9. body: 'Set up table'
  10. }]
  11. // const findNote = function (notes, noteTitle) {
  12. // const index = notes.findIndex(function (note, index) {
  13. // let currentTitle = String(note.title).toLowerCase()
  14. // console.log(currentTitle)
  15. // return currentTitle === noteTitle.toLowerCase()
  16. // })
  17. // return notes[index]
  18. // }
  19. const findNote = function (notes, noteTitle) {
  20. return notes.find(function (note, index) {
  21. let currentTitle = String(note.title).toLowerCase()
  22. console.log(currentTitle)
  23. return currentTitle === noteTitle.toLowerCase()
  24. })
  25. }
  26. const findNotes = function (notes, query){
  27. return notes.filter(function (note, index) {
  28. const isTitleMatch = note.title.toLowerCase().includes(query.toLowerCase())
  29. const isBodyMatch = note.body.toLowerCase().includes(query.toLowerCase())
  30. // const isTitleMatch = String(note.title).toLowerCase().includes('ne')
  31. // const isBodyMatch = String(note.body).toLowerCase().includes('ne')
  32. return isTitleMatch || isBodyMatch
  33. })
  34. }
  35. console.log(findNotes(notes, 'eating'))
  36. // const note = findNote(notes, 'office other modifications')
  37. // console.log(note)
  38. // console.log(notes.length)
  39. // console.log(notes)
  40. // for (let count = 0; count <= 2; count++) {
  41. // console.log(count)
  42. // }
  43. // for (let count = 0; count < notes.length; count++) {
  44. // console.log(notes[count])
  45. // }
  46. // const index = notes.findIndex(function (note, index) {
  47. // console.log(note)
  48. // return note.title === 'Habits to work on'
  49. // })
  50. // console.log(index)