Last active
April 17, 2018 10:21
-
-
Save JakeDuke/bd1a4956d315bc2b4aada5ffb03c8705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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