Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Last active March 13, 2018 23:33
Show Gist options
  • Select an option

  • Save DavidMellul/606e8ad6f2f1d377ae930e36f3600b90 to your computer and use it in GitHub Desktop.

Select an option

Save DavidMellul/606e8ad6f2f1d377ae930e36f3600b90 to your computer and use it in GitHub Desktop.
// A dead-easy data structure representing a database
let ArticlesDatabase = {
content: [
{
'id': 1,
'title': 'Insane prank, I broke my leg watch this'
},
{
'id': 2,
'title': 'Cops arrested me, discover why'
},
{
'id': 3,
'title': 'Look at this, the second is unbelievable'
}
],
getAll: function() { return this.content },
add: function(article) { this.content.push(article); }
};
// Let's use our database
console.log(ArticlesDatabase.getAll());
// => Exactly what you expected, the array with the 3 objects
ArticlesDatabase.add(
{
'id':4,
'title': 'Nice one !'
});
console.log(ArticlesDatabase.getAll());
// => The array with 4 objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment