---
id: 69bac0a011a9c1f735d306c2
title: Step 18
challengeType: 1
dashedName: step-18
---

# --description--

Process the input gate for the current tick by calling `processGateFlow()` with `gate` and `tickIndex` and assigning the result to a variable named `result`.

# --hints--

Your `handleGateAtTick` function should call the `processGateFlow()` method.

```js
const testGates = [
  { id: "North", capacity: 5, queue: [3, 6, 2, 4] },
  { id: "East", capacity: 3, queue: [2, 4, 3, 5] },
  { id: "South", capacity: 4, queue: [1, 2, 3, 1] },
  { id: "West", capacity: 2, queue: [4, 1, 2, 3] }
];
const throughputSummary = { North: 0, East: 0, South: 0, West: 0 };
const originalProcessGateFlow = processGateFlow;

let called = false;
try {
  processGateFlow = function (...args) {
    called = true;
    return originalProcessGateFlow(...args);
  };
  const northGate = testGates[0];
  handleGateAtTick(testGates, northGate, 0, throughputSummary);
  assert.isTrue(
    called,
    "handleGateAtTick should call processGateFlow()"
  );
} catch (err) {
  assert.fail(err);
} finally {
  processGateFlow = originalProcessGateFlow;
}
```

You should call `processGateFlow()` with `gate` and `tickIndex` and assign the result to a variable named `result`. 

```js
const rawFuncStr = __helpers.removeJSComments(handleGateAtTick.toString());
assert.match(
  rawFuncStr,
  /(var|const|let)\s+result/,
  "You must have at least one space between the declaration keyword (let/const) and 'result'."
);

const cleaned = __helpers.removeWhiteSpace(rawFuncStr);
const solution = /(var|const|let)result=processGateFlow\(gate,tickIndex\);?}$/;

assert(
  solution.test(cleaned),
  "Inside your `handleGateAtTick` function, call `processGateFlow()` with `gate` and `tickIndex` and assign the result to a variable named `result`."
);
```

# --seed--

## --seed-contents--

```js
const morningGates = [
  { id: "North", capacity: 5, queue: [3, 6, 2, 4] },
  { id: "East", capacity: 3, queue: [2, 4, 3, 5] },
  { id: "South", capacity: 4, queue: [1, 2, 3, 1] },
  { id: "West", capacity: 2, queue: [4, 1, 2, 3] },
];

const nightGates = [
  { id: "North", capacity: 4, queue: [6, 2, 5, 1] },
  { id: "East", capacity: 2, queue: [3, 3, 4, 2] },
  { id: "South", capacity: 5, queue: [2, 1, 2, 3] },
  { id: "West", capacity: 3, queue: [5, 2, 1, 4] },
];

function initializeThroughput(gates) {
  const summary = {};
  for (const gate of gates) {
    summary[gate.id] = 0;
  };
  return summary;
}

function processGateFlow(gate, tickIndex) {
  let currentTickQueue = gate.queue[tickIndex];
  let processed = 0;
  while (currentTickQueue > 0 && processed < gate.capacity) {
    currentTickQueue--;
    processed++;
  }
  return {
    processed: processed,
    overflow: currentTickQueue
  };
}

function rerouteOverflow(gates, currentGate, tickIndex, overflowAmount) {
  const currentIndex = gates.indexOf(currentGate);
  const nextGateIndex = (currentIndex + 1) % gates.length;
  gates[nextGateIndex].queue[tickIndex] += overflowAmount;
  console.log(
    overflowAmount + " attendees rerouted to " +
    gates[nextGateIndex].id
  );
}

function handleGateAtTick(gates, gate, tickIndex, throughputSummary) {
  console.log("\nProcessing " + gate.id + "...");
  console.log(
    gate.queue[tickIndex] + " attendees arriving."
  );
--fcc-editable-region--
  
--fcc-editable-region--
}
```
