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

152
Visualizações
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 à 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