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

260
Visualizações
Need help comparing an object generated from a form submission agaisnt a previous submission

So I am building a data collection software that relies heavily on forms and form validations. I have currently built up dynamic forms with Formik and Yup with individual validation but im looking to dive deeper into validating the users current input agaisnt a previous input to make sure the value of the same key from the objects are incrementing or decrementing based on the form settings.

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

I want to setup some sort of system to compare these two objects to validate that the users current submission for NumberOne in Object Two is properly incrementing higher than the previous value in Object One. If said value is not incrementing then it would return an error telling the user the data is not valid.

If someone could help me brainstorm on how to acheive this or point me in the proper direction i would greatly appreciate it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With your example, you can do a basic function which compare NumberOne values:

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

const check = (one, two) => {
if (two.NumberOne > one.NumberOne)
    console.log('ok');
else
    console.log('ko');
}

check(ObjOne, ObjTwo);

In this example, only NumberOne values are compared but you can do a more complicated function to check all keys. This example just answer to your specific question.

This does the job for the given example:

const check = (one, two) => {
if (two.NumberOne < one.NumberOne || two.NumberTwo < one.NumberTwo || two.NumberThree < one.NumberThree)
    console.log('ko');
else
    console.log('ok');
}
about 4 years ago · Juan Pablo Isaza Relatório
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