Function to determine what color shirt somebody should wear to a football game depending on what seat they have I was tasked with writing a function to find what color shirt someone should wear to our college football game depending on what seat they sit in. Here is the function I came up with:

function getColor(section, row) {
  const colorA = "orange";
  const colorB = "white";
  section = section.toUpperCase();

  /* Case 1: Section is a special section */
  if (section.includes("TER") || section.includes("WC") || section.includes("EC")) {
    /* Numbers in special sections are guaranteed to be single digit,
       So just grab the last character in the section. */
    const number = section.slice(-1);
    // Even numbers are colorB, odd are colorA
    return (number % 2 === 0) ? colorB : colorA;
  }
  /* Case 2: Section is a single letter (No numbers) */
  else if  (section.length === 1) {
    /* A through Q have different row numbers than R through W */
    const section_divider = getSectionDivider(section);

    /* Odd-lettered (A, C, etc.) sections are colorA when above
       the section divider. Even-lettered section are colorB when
       above the section divider. */
    if (section.charCodeAt(0) % 2 === 0) {
      return (row &gt;= section_divider) ? colorB : colorA;
    } else {
      return (row &gt;= section_divider) ? colorA : colorB;
    }
  }
  /* Case 3: Section is two letters (No numbers) */
  else if (section.length == 2 &amp;&amp; section.charAt(0) &gt;= 'A' &amp;&amp; section.charAt(0) &lt;= 'Z'  &amp;&amp;
           section.charAt(1) &gt;= 'A' &amp;&amp; section.charAt(1) &lt;= 'Z') {
    /* Double lettered sections are always the same color as the
       single letter's bottom row */
    return getColor(section.charAt(0), 0);
  }
  /* Case 4: Section is a single letter followed by a number */
  else if (!isNaN(section.slice(1))) {
    /* Row is WC */
    if (isNaN(row)) {
      /* WC rows should just match the section below them */
      return getColor(section, 0);
    }

    /* X3 and Z15 are special cases where the whole section isn't one
       color. They are both colorB above the section divider and colorA below. */
    if (section === "X3" || section === "Z15") {
      const section_divider = 16; // Just in case it changes in the future.
      return (row &lt;= section_divider) ? colorA : colorB;
    } else {
      /* This is the number. (i.e. X4 =&gt; 4, Z13 =&gt; 13) */
      const number_in_section = parseInt(section.slice(1));
      return (number_in_section % 2 === 0) ? colorA : colorB;
    }
  }
  /* Case 5: Section is a double letter followed by a number */
  else {
    /* Double-letter-number sections are always the opposite of the
       single-letter version of its self's top row.
       (i.e. XX13 is whatever X13's top row isn't) */
    return getColor(section.slice(1), 1000) === colorA ? colorB : colorA;
  }
}


Is there a better way of solving this problem? Is the code clear?
I see 2 points where you can work to increase the quality of your code.


simplify some conditions check 
get rid of comments


simplify some conditions check

Consider the following code:

/* Case 3: Section is two letters (No numbers) */
else if (section.length == 2 &amp;&amp; section.charAt(0) &gt;= 'A' &amp;&amp; section.charAt(0) &lt;= 'Z'  &amp;&amp;
       section.charAt(1) &gt;= 'A' &amp;&amp; section.charAt(1) &lt;= 'Z') {


I think you could make it shorter with just a regular expression:

else if (section.match(^[A-Z]{2}$)) {


It is not just short and fast to read, but, in this case, it show you what is the "rule" that the string should satisfy.

get rid of comments

Your code is full of comments, and that made it difficult to reed.

Consider that many developer, me included, don't trust the comments and read it just when something weird happened. And in this case too there are very few times the comments helps.

The reason is you should update the comments as you update the code, but this never happened as it is more work and you don't have time.

Compilers or interpeter never care the comments.

The other point is that the developers could read and understand the code, and your effort should put in made the code readable for human beings.

Let me show some examples.

  /* Case 1: Section is a special section */
  if (section.includes("TER") || section.includes("WC") || section.includes("EC")) {


Consider the followhing change. As you can see you don't need the comment any more.

if (isASpecialSection(section)) {

...

function isASpecialSection(section) {
    return section.includes("TER") || section.includes("WC") || section.includes("EC");
}


Another example:

/* Case 2: Section is a single letter (No numbers) */
else if  (section.length === 1) {


Even the condition is short, you should use the same approach, as it is not clear in which case you are here.

Look at the comment, it "lied", because you just check that the string have length 1, not that is only letters. Maybe you don't have the case today, but data could change.

So remove the comment and change the check:

else if (section.match(/^[A-Z]$/)) {


Not all comments are bad, you should avoid those comments that tell what the code does, because you can read the code and so it is a waste of time for the developers that read your code.

Too many comments like in your code make difficult to read the code.
To put all those comments you break the indentation.

Try to make your code more readable by using proper names or functions to encapsulate complex conditions.

Naming is hard and take time, I know, but it pay back.