6080-a3-BigBrain / backend / src / custom.js
custom.js
Raw
/*
 For a given data structure of a question, produce another
 object that doesn't contain any important meta data (e.g. the answer)
 to return to a "player"
*/
export const quizQuestionPublicReturn = question => {
  console.log('See question: ', question);

  const publicQ = JSON.parse(JSON.stringify(question));
  publicQ.answers.forEach(a => {delete a.isCorrect;});
  return publicQ;
};

/*
 For a given data structure of a question, get the IDs of
 the correct answers (minimum 1).
*/
export const quizQuestionGetCorrectAnswers = question => {
  const correctAnswers = question.answers.filter((a) => a.isCorrect === true)
  const correctAnswersIds = correctAnswers.map((a) => a.answerNum)
  console.log(correctAnswersIds)
  return correctAnswersIds // For a single answer
};

/*
 For a given data structure of a question, get the IDs of
 all of the answers, correct or incorrect.
*/
export const quizQuestionGetAnswers = question => {
  return question.answers.map((a) => a.answerNum) // For a single answer
};

/*
 For a given data structure of a question, get the duration
 of the question once it starts. (Seconds)
*/
export const quizQuestionGetDuration = question => {
  return question.timeLimit;
};