Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda