Skip to content

Instantly share code, notes, and snippets.

@JakeDuke
Last active April 17, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JakeDuke/bd1a4956d315bc2b4aada5ffb03c8705 to your computer and use it in GitHub Desktop.
Save JakeDuke/bd1a4956d315bc2b4aada5ffb03c8705 to your computer and use it in GitHub Desktop.
var app = {
db: {},
next_id: 0,
create: function(newThing) {
if(newThing !== ''){
this.db[this.next_id] = newThing;
this.next_id ++;
return 'NEW OBJECT WAS CREATED' ;
}else{
return 'Error';
}
},
read: function(ID) {
if(this.db[ID]){
return this.db[ID] ;
} else {
return 'NOT FOUND' ;
}
},
update: function(ID, new_value) {
if(new_value && this.db[ID]){
this.db[ID] = new_value;
return 'THING WAS UPDATED';
}else if (!this.db[ID]){
return 'unknown ID';
}else if(!new_value){
return 'invalid input';
} else {
return'ALL BAD';
}
},
delete: function(ID) {
if(this.db[ID]){
this.db[ID] = undefined,
console.log('APP WAS DELETED');
} else{
console.log('UNKNOWN ID');
}
}
};
app.create('lol');
console.log(app.db);
console.log(app.update(0,'ololo'));
console.log(app.update('ololo'));
console.log(app.update(0));
console.log(app.db);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment