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.