Skip to content

Instantly share code, notes, and snippets.

@EduceHealth
Created June 7, 2014 02:21
Show Gist options
  • Save EduceHealth/d703205fc1be783985ce to your computer and use it in GitHub Desktop.
Save EduceHealth/d703205fc1be783985ce to your computer and use it in GitHub Desktop.
Arrays vs Objects.
this.addToResponses = function(responses, interventionId, questiongroupId, questiongroupInstanceId, questionId, response) {
if (!responses.questiongroups) {
responses.interventionId = interventionId
responses.questiongroups = new Array()
}
if(!responses.questiongroups[????????]) {
responses.questiongroups.push({Id: questiongroupId, questiongroupInstances:{}})
}
if (!responses.questiongroups[????????].questiongroupInstances[questiongroupInstanceId]){
responses.questiongroups[????????].questiongroupInstances.push({Id: questiongroupInstanceId, questions:{}})
}
if (!responses.questiongroups[????????].questiongroupInstances[????????].questions[????????]){
responses.questiongroups[????????].questiongroupInstances[????????].questions.push({Id:questionId, response: response})
}
}
this.addToResponses = function(responses, interventionId, questiongroupId, questiongroupInstanceId, questionId, response) {
if (!responses.questiongroups) {
responses.interventionId = interventionId
responses.questiongroups = {}
}
if(!responses.questiongroups[questiongroupId]) {
responses.questiongroups[questiongroupId] = {Id: questiongroupId, questiongroupInstances:{}}
}
if (!responses.questiongroups[questiongroupId].questiongroupInstances[questiongroupInstanceId]){
responses.questiongroups[questiongroupId].questiongroupInstances[questiongroupInstanceId] = {Id: questiongroupInstanceId, questions:{}}
}
if (!responses.questiongroups[questiongroupId].questiongroupInstances[questiongroupInstanceId].questions[questionId]){
responses.questiongroups[questiongroupId].questiongroupInstances[questiongroupInstanceId].questions[questionId] = {Id:questionId, response: response}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment