| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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 sortNotes = function (notes) {
- notes.sort(function (a, b){
- if (a.title.toLowerCase() < b.title.toLowerCase()) {
- return -1
- } else if (b.title.toLowerCase() < a.title.toLowerCase()) {
- return 1
- } else {
- return 0
- }
- })
- }
- 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)
- sortNotes(notes)
- console.log(notes)
|