Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Slot Filling Algorithm in Javascript
const CleanTable = [{seat: 1, group: 0}, {seat: 2, group: 0}, {seat: 3, group: 0}, {seat: 4, group: 0}, {seat: 5, group: 0}];

function groupCalculator(Table, Group, Index) {
  const emptySpace = Table.filter((s) => s.group === 0)
  const occupied = Table.filter((s) => s.group !== 0);
  
  if (Group > emptySpace.length) return "no Free Slots";
  else {
    const fillSeats = emptySpace.slice(0, Group).reduce((newArr, current) => {
      const { seat } = current;
      const object = { seat: seat, group: Index };
      const arr = [object, ...newArr];
      return arr.sort((a, b) => a.seat > b.seat);
    }, []);

    const slice = Table.slice(Group);
    const merge = [...fillSeats, ...slice];

    return merge ;
  }
}

I am currently working on an algorithm that assigns Slots A to a group B. When the Slots are occupied, they are marked with a group ID. If the group leaves their seats, they can be reassigned.

My idea was to use an array of objects for this purpose and fill it up sequentially.

In the first round everything works fine (https://jsfiddle.net/5b3a1try/14/ "Code e Exampel") ), but after the second round nothing works anymore.

Am I on the right track here, or am I going about this the wrong way?

I use this function in a React app, which means that the Executiontriggered via a forum.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!