Next page | Contents page |

Completing a suit

It is really quite easy to check whether a column ends with a full suit, from King down to Ace. Start at the bottom end of the column and work upwards:

Column.prototype.endsWithFullSuit = function ()
{ console.log ("endsWithFullSuit");
  const L1 = this.CARDS.length - 1;
  if (L1 < 12) return false;
  const SUIT = this.CARDS [L1].suit;
  for (var i = L1, j = 1; j <= 13; i--, j++)
  { if (this.CARDS [i].suit !== SUIT
     || this.CARDS [i].value !== j)
      return false;
  return true;

I have temporarily included a console output to check when the method is invoked. Causing that to happen is not easy with the program as it is so far. We need to set up some special arrangement of cards to enable it to happen when a few cards are moved.

The next question is what to do when the method returns true. We will defer that. First we need to think more about testing.

Next page | Contents page |