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

258
Vistas
Check if a element in array exists but not perform any task javascript

So I have been tasked with making a basic workflow engine. I have it checking the config file for dependencies and then performing the next function. what I would like to is check to see if the element already exists and not push it to the output array. I have tried .includes() and .indexOf() but I cant seem to get them to work.

const TestWorkflowConfig = {
  insertDetails: {
    dependencies: [],
    workflow: { name: "updateRow", id: 10 },
    description: "This is a test function where details need to be entered (row update)",
    data: {},
    taskName: "insertDetails",
  },

  detailsConfirmed: {
      { insertDetails: { isRequired: true; } }
dependencies: ["insertDetails"],
  workflow: { name: "updateRow", id: 10; },
description: "this is to confirm details (update row status)",
  data: {},
taskName: "detailsConfirmed",
  },

sendConfirmationEmail: {

  dependencies: ["detailsConfirmed"],
    workflow: { name: "sendEmail", id: 8; },
  description: "this is a test email to send out to confirm details (send email workflow)",
    data: { name: "james", email: "james@email.com", body: "this is a test email please ignore"; },
  taskName: "sendConfirmationEmail",
  },
};

const taskQueue = [
  {
    "processName": "sendConfirmationEmail",
    "isComplete": false
  },
  {
    "processName": "detailsConfirmed",
    "isComplete": false
  },
  {
    "processName": "insertDetails",
    "isComplete": true
  }
];
const workflowTaskQueue = [];
const config = TestWorkflowConfig;
const completedJobs = [];

for (const element of taskQueue) {
  if (element.isComplete === true) {
    completedJobs.push(element.processName);
  }
}

for (const element in config) {

  if (config[element].dependencies <= 0) {

    // I would like to check if the "config[element]" is in the completedJobs array and only push if it is not there.

    workflowTaskQueue.push({ json: config[element] });
  } else {
    const dependencies = config[element].dependencies;

    const dep = [];
    for (const el of dependencies) {
      dep.push(el);
      const result = dep.every((i) => completedJobs.includes(i));
      if (result === true) {

        //  and again I would like to check if the "config[element]" is in the completedJobs array and only push if it is not there

        workflowTaskQueue.push({ json: config[element] });
      }
    }

    console.log("taskQueue: " + taskQueue);
    console.log("completedJobs: " + completedJobs);
    console.log("output:" + workflowTaskQueue);
  }
}

as always any help is greatly appreciated.

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