text: const app = require("express")()
  const express = require("express")
  app.use(express.json())
  
  let data = [
      {
          id: 1,
          title: "Surprised Pikachu"
      },
      {
          id: 2,
          title: "Pablo Francisco"
      },
      {
          id: 3,
          title: "Kylo Ren Meme"
      }
  ]
  
  function createMeme(title) {
      id = data.length + 1
      data.forEach(meme => {
          if (meme.id == id) {
              id++
          }
      })
      const newMeme = {
          id: id,
          title: title
      }
      return newMeme
  }
  
  app.get("/dankmemes", (req, res) => {
      res.send({data})
  })
  
  app.get("/dankmemes/:id", (req, res) => {
      res.send(data[req.params.id-1])
  })
  
  app.post("/dankmemes/", (req, res) => {
      data.push(createMeme(req.body.title)) 
          ? res.status(201).send({id: id}) : res.sendStatus(500)
  })
  
  // Changes title, retains id
  app.patch("/dankmemes/:id", (req, res) => {
      data.forEach(meme => {
          if (meme.id == req.params.id) {
              meme.title = req.body.title
              res.sendStatus(201) 
          }
      })
      res.sendStatus(404)
  }) 
  
  // Replaces meme at index with meme (hence the - in this case - arbitrary new ID returned)
  app.put("/dankmemes/:id", (req, res) => {
      data.forEach((meme, index) => {
          if (meme.id == req.params.id) {
              newMeme = createMeme(req.body.title)
              data[index] = newMeme
              res.status(200).send(
                  {
                      id: newMeme.id
                  })
          }
      })
      res.sendStatus(404)
  })
  
  // Splices/deletes meme at indexof given id. returns 204 if successful
  app.delete("/dankmemes/:id", (req, res) => {
      data.splice(data.map(meme => meme.id).indexOf(parseInt(req.params.id)), 1) ? res.sendStatus(204) : res.sendStatus(404)
  })
  
  app.listen(8080, (error) => {
      if (error) {
          console.log(error)
      }
      console.log ("Server is running on port", 8080)
  })