Skip to content

Instantly share code, notes, and snippets.

@scastiel
Created April 3, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scastiel/8a75f9acd953b78707a477b540358c19 to your computer and use it in GitHub Desktop.
Save scastiel/8a75f9acd953b78707a477b540358c19 to your computer and use it in GitHub Desktop.
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