Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

70
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.

7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.