Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 18, 2021 13:35
Show Gist options
  • Select an option

  • Save codecademydev/e47a7f2c7bdc54811887780bcab5d3a7 to your computer and use it in GitHub Desktop.

Select an option

Save codecademydev/e47a7f2c7bdc54811887780bcab5d3a7 to your computer and use it in GitHub Desktop.
Codecademy export
const express = require('express');
const app = express();
const PORT = process.env.PORT || 4001;
const puddingFlavors = ['chocolate', 'banana', 'butterscotch', 'pistachio'];
const findPuddingIndex = (name) => {
return puddingFlavors.indexOf(name);
}
const deletePuddingAtIndex = (index) => {
puddingFlavors.splice(index, 1);
}
// Your code here!
app.delete('/puddings/:flavor', (req, res, next) => {
const isAvailable = findPuddingIndex(req.params.flavor);
if(isAvailable !== -1) {
deletePuddingAtIndex(isAvailable);
res.status(204).send();
} else {
res.status(404).send();
}
})
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment