Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda