Build a Festival Crowd Flow Simulator - Step 13

Tell us what’s happening:

I understand that i must use the nextGateIndex to access the queue but I am a little bit lost regarding on adding using the tick index with the overflowAmount. I thought it would meant using splice but that didnt work so I am a little bit confused on what exactly this workshop is asking of me. The help is greatly appreciated!

Your code so far

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;
// User Editable Region
  gates[nextGateIndex].queue.splice(tickIndex, 0, overflowAmount);
// User Editable Region
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0

Challenge Information:

Build a Festival Crowd Flow Simulator - Step 13

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-festival-crowd-flow-simulator/69bac03ae5faf2979a3339ff.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @gladennn,

Wouldn’t you use the tickIndex to access a value in the queue array and add the overflowAmount to that value?

Happy coding