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

154
Vistas
if statements vs shortened if statements

forgive me if this is a dumb question but im trying to find the difference between these 2 statements. I wrote the first code and got the 2nd code from stack overflow. Of course the stack overflow works but when I try and do it the long way, it won't run. What am I doing wrong? What's the difference in our code that makes mine break??

function compareTriplets(a, b) {
    // Write your code here
    let score = [0,0];
for (let i = 0; i < a.length; i++) {
    if (a[i] > b[i]) {
        return score[0]++;
    } else if (a[i] < b[i]) {
        return score[1]++;
    } else return ""
}
return score;
}

//this is the code from stack overflow that works. I can't find the difference.

function compareTriplets(a, b) {
let score = [0,0]

for (let i = 0; i < a.length; i++)
a[i] > b[i] ? score[0]++ : a[i] < b[i] ? score[1]++ : ""
return score

Here is where I'm getting the question from.

Please let me know if you have any ideas. Thanks for your time.

about 4 years ago · Santiago Trujillo
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