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

101
Vistas
Evaluate and give the output in 2 arrays

const orderList = [["paul", "enter"],["jenny", "exit"],["paul", "exit"],["phil", "enter"],["shriya", "exit"],["shriya", "enter"],["shriya", "exit"],["paul", "enter"]["phil", "exit"],["Dan", "exit"],["Dan", "enter"]] Following the above order pls evaluate and give the output in 2 arrays, one for wrong entry and other for wrong exit. Order is important. Example: Paul has entered and exited which is correct. Again he has entered but didn't exit. So he comes in wrong exited array.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I guessed it correctly then this is what you are looking for.

function check(orderList) {
    eventCount = {};
for(let i = 0; i < orderList.length; i++){
if(orderList[i]){
     let person = orderList[i][0];
    console.log(person, "--> ",orderList[i][1] );
    if(!eventCount.hasOwnProperty(person)){
            eventCount[person] = 0;
        }
    if(orderList[i][1] === "enter"){
        eventCount[person] = eventCount[person]+1;
    } else {
        eventCount[person] = eventCount[person]-1;
    }
}
    
}
let right = [];
let wrong = [];
for (const person in eventCount) {
  if(eventCount[person] === 0) {
      right.push(person);
  }else {
         wrong.push(person);
    }
}    
console.log("right -> ", right);
console.log("wrong -> ", wrong);
}

const orderList = [["paul", "enter"],
                    ["jenny", "exit"],
                    ["paul", "exit"],
                    ["phil", "enter"],
                    ["shriya", "exit"],
                    ["shriya", "enter"],
                    ["shriya", "exit"],
                    ["paul", "enter"],["phil", "exit"],["Dan", "exit"],["Dan", "enter"]];

check(orderList);

about 4 years ago · Juan Pablo Isaza Denunciar
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