Repository: freeCodeCamp/freeCodeCamp
File: client/src/templates/Challenges/exam/show.tsx (TypeScript)

Code before:
      t
    } = this.props;

    const {
      examTimeInSeconds,
      currentQuestionIndex,
      generatedExam,
      userExam,
      showResults
    } = this.state;

    const incompletePrequisites = [];
    let qualifiedForExam = true;

    for (let i = 0; i < prerequisites.length; i++) {
      const prerequisiteChallenge = prerequisites[i];
      const isPrerequisiteCompleted = completedChallenges.find(
        (completedChallenge: CompletedChallenge) =>
          prerequisiteChallenge.id === completedChallenge.id
      );

      if (!isPrerequisiteCompleted) {
        incompletePrequisites.push(prerequisites[i].title);
        qualifiedForExam = false;
      }
    }

    const blockNameTitle = `${t(
      `intro:${superBlock}.blocks.${block}.title`
    )}: ${title}`;
    const windowTitle = `${blockNameTitle} | freeCodeCamp.org`;
    const ariaLabel = t('aria.answer');

    return examInProgress ? (
      <Grid>
        <Row>
          <Spacer size='medium' />
          <Col md={10} mdOffset={1} sm={10} smOffset={1} xs={12}>
            {showResults ? (
              <ExamResults
                title={title}
                submitExamResults={this.submitExamResults}
              />
            ) : (
              <div className='exam-wrapper'>
                <div className='exam-header'>
                  <div>{title}</div>
                  <span>|</span>
                  <div> Time: {formatSecondsToTime(examTimeInSeconds)}</div>
                  <span>|</span>
                  <div>

Review comment (suggestion):
```suggestion
    const missingPrequisites = prerequisites.filter(
      prerequisite =>
        !completedChallenges.find(({ id }) => prerequisite.id === id)
    );

    const qualifiedForExam = missingPrequisites.length === 0;
```
Now you need the list of missing prequisites, the declarative approach looks even nicer imo.

Code after:
      t
    } = this.props;

    const {
      examTimeInSeconds,
      currentQuestionIndex,
      generatedExam,
      userExam,
      showResults
    } = this.state;

    const missingPrequisites = prerequisites.filter(
      prerequisite =>
        !completedChallenges.find(({ id }) => prerequisite.id === id)
    );

    const qualifiedForExam = missingPrequisites.length === 0;

    const blockNameTitle = `${t(
      `intro:${superBlock}.blocks.${block}.title`
    )}: ${title}`;
    const windowTitle = `${blockNameTitle} | freeCodeCamp.org`;
    const ariaLabel = t('aria.answer');

    return examInProgress ? (
      <Grid>
        <Row>
          <Spacer size='medium' />
          <Col md={10} mdOffset={1} sm={10} smOffset={1} xs={12}>
            {showResults ? (
              <ExamResults
                title={title}
                submitExamResults={this.submitExamResults}
              />
            ) : (
              <div className='exam-wrapper'>
                <div className='exam-header'>
                  <div>{title}</div>
                  <span>|</span>
                  <div> Time: {formatSecondsToTime(examTimeInSeconds)}</div>
                  <span>|</span>
                  <div>
                    Question {currentQuestionIndex + 1} of{' '}
                    {generatedExam.length}
                  </div>
                </div>
                <hr />
                <Spacer size='medium' />

                <div className='exam-questions'>
                  <div>{generatedExam[currentQuestionIndex].question}</div>