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

130
Vistas
Repeat same numbers after particular number

I have a logic like user gives a date. I compare with current date and calculate the difference. According the difference, I send back them a message. I have set of 4 messages. If the difference is 1 then I send 1st message from set of 4. My confusion is, If the difference is 5 then it should send 1st message, if difference is 6 then it should send 2nd message. Because I have only 4 messages. Basically I'm trying to create a method where I give 5 as parameter and I give back 1 as result. Give 6 and get 2 and it goes on.

Code

var userDate;
var todayDate = new Date();
var diff = moment.duration(moment(userDate).diff(moment(todayDate)));
if(diff > 4){
   diff = 1;
}

This logic didn't worked out for me. Please help me out.

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

0

Simplest option is the remainder operator:

function getDiff(num) {
  return num % 5
}

Or the same but more verbose:

function getDiff(num) {
  return num - (Math.floor(num/5) * 5)
}
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