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

151
Views
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
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!