notes.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 sortNotes = function (notes) {
  20. notes.sort(function (a, b){
  21. if (a.title.toLowerCase() < b.title.toLowerCase()) {
  22. return -1
  23. } else if (b.title.toLowerCase() < a.title.toLowerCase()) {
  24. return 1
  25. } else {
  26. return 0
  27. }
  28. })
  29. }
  30. const findNote = function (notes, noteTitle) {
  31. return notes.find(function (note, index) {
  32. let currentTitle = String(note.title).toLowerCase()
  33. console.log(currentTitle)
  34. return currentTitle === noteTitle.toLowerCase()
  35. })
  36. }
  37. const findNotes = function (notes, query){
  38. return notes.filter(function (note, index) {
  39. const isTitleMatch = note.title.toLowerCase().includes(query.toLowerCase())
  40. const isBodyMatch = note.body.toLowerCase().includes(query.toLowerCase())
  41. // const isTitleMatch = String(note.title).toLowerCase().includes('ne')
  42. // const isBodyMatch = String(note.body).toLowerCase().includes('ne')
  43. return isTitleMatch || isBodyMatch
  44. })
  45. }
  46. // console.log(findNotes(notes, 'eating'))
  47. // const note = findNote(notes, 'office other modifications')
  48. // console.log(note)
  49. // console.log(notes.length)
  50. // console.log(notes)
  51. // for (let count = 0; count <= 2; count++) {
  52. // console.log(count)
  53. // }
  54. // for (let count = 0; count < notes.length; count++) {
  55. // console.log(notes[count])
  56. // }
  57. // const index = notes.findIndex(function (note, index) {
  58. // console.log(note)
  59. // return note.title === 'Habits to work on'
  60. // })
  61. // console.log(index)
  62. sortNotes(notes)
  63. console.log(notes)