index.js
// append (functionally) an answer to a stack, making sure question/answer is valid
append (functionally) an answer to a stack, making sure question/answer is valid
append ( functionally ) an answer to a stack making sure question / answer is valid
function pushAnswer(answerStack, questionId, answerId) {
    const q = lookupQuestion(questionId);
    if (q) {
      const a = q.answers.find(a => a.value === answerId);
      if (a) {
        return [{ questionId, answerId }, ...answerStack];
      }
      else {
        throw new Error(`can't find answer ${answerId} for ${questionId}`);
      }
    }
    else {
      throw new Error(`can't find question ${questionId}`);
    }
  }
function pushAnswer ( answerStack , questionId , answerId ) { const q = lookupQuestion ( questionId ) ; if ( q ) { const a = q . answers . find ( a => a . value === answerId ) ; if ( a ) { return [ { questionId , answerId } , ... answerStack ] ; } else { throw new Error ( ` ${ answerId } ${ questionId } ` ) ; } } else { throw new Error ( ` ${ questionId } ` ) ; } }
append (functionally) an answer to a stack, making sure question/answer is valid
append ( functionally ) an answer to a stack making sure question / answer is valid
// console.debug(answerStack, questionId, answerId); // it was a valid answer