1

How can I convert his constant into a function? I think is better to have a function that a constant this long. It does a filter and then a map.

const cells = upcoming
  .filter(clinic => {
    if (showAll) return true;
    if (
      clinic.staff.teamLeadStaffed !== null &&
      clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
    )
      return false;
    return true;
  })
  .map(clinic => {
    const [color, reason] = this.getColorAndReason(clinic);

I tried something like this but it didn't work

  renderCell(upcoming) {
    return (
      upcoming
        .filter(clinic => {
          if (showAll) return true;
          if (
            clinic.staff.teamLeadStaffed !== null &&
            clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
          )
            return false;
          return true;
        })
        .map(clinic => {
          const [color, reason] = this.getColorAndReason(clinic);
    )
  }
1
  • 2
    you are missing the closing brackets for the map function. }) Commented Jul 11, 2018 at 18:10

1 Answer 1

1
function cells() {
  return upcoming
    .filter(clinic => {
      if (showAll) return true;
      if (
        clinic.staff.teamLeadStaffed !== null &&
        clinic.staff.techsStaffed.length === clinic.staff.techsNeeded
      )
        return false;
      return true;
    })
    .map(clinic => {
      const [color, reason] = this.getColorAndReason(clinic);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.