Created
April 3, 2017 14:13
-
-
Save scastiel/8a75f9acd953b78707a477b540358c19 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
const data = { | |
persons: [ | |
{ id: 0, name: "Sherlock Holmes", numbers: ["555-0101", "555-0199"] }, | |
{ id: 1, name: "John Watson", numbers: ["555-0102", "555-0198"] } | |
], | |
groups: [ | |
{ id: 0, name: "Londonians", personsIds: [0, 1] }, | |
{ id: 1, name: "Doctors", personsIds: [1] } | |
] | |
} | |
const lastPersonId = 1 | |
const lastGroupId = 1 | |
function getPerson(personId) { | |
return data.persons.find(p => p.id === personId) | |
} | |
// | |
function createPerson(personData) { | |
const newPerson = Object.assign({ id: lastPersonId + 1 }, personData) | |
lastPersonId++ | |
data.persons.push(newPerson) | |
return newPerson | |
} | |
module.exports.getPerson = getPerson | |
module.exports.createPerson = createPerson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment