Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
Sentencia lógica IF Significado

Estoy trabajando en un proyecto, pero me quedé perplejo al ver este fragmento de código si ((array.length - 1 - i) % 2 === 1) ¿Tengo curiosidad por saber cómo funciona?

 const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]; const validateCred = (array) => { let total = 0; for (var i = array.length - 1; i >= 0; i--) { // console.log(array[i]) if ((array.length - 1 - i) % 2 === 1) { /*I would like to know what does this do when put in a if statment array.length - 1 - i */ array[i] *= 2; // console.log(array[i]) if (array[i] > 9) { array[i] -= 9; } } total += array[i] console.log(total) } return total % 10 === 0; }; console.log(validateCred(valid1))

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • array.length - 1 : el último índice de la matriz
  • lastIndex - i : trabaje a través de la matriz de atrás hacia adelante (típicamente)
  • someIndex % 2 === 1 : ¿el módulo de índice 2 es igual a 1 (es decir, es impar?)

Pero luego el ciclo itera desde el último índice hasta el primer índice, por lo que el - i solo lo hace iterar de adelante hacia atrás nuevamente. Lo cual parece innecesariamente complejo.

Este código es bastante raro...

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!