2 ways to do something, which is the difference?

Hi, there are 2 ways to do this thing, (a challenge of JavaScript)
the lesson explain the second way, but i find simpler the first .
it’s correct?

//test 1

function checkPositive1(arr) {
  // Only change code below this line
return arr.every(num => num > 0);
  // Only change code above this line
}
console.log(checkPositive1([1, 2, 3, 4, 5]));

//test 2

function checkPositive2(arr) {
  // Only change code below this line
  return arr.every(function(currentValue) {
     return currentValue < 10;
     });
  // Only change code above this line
}
console.log(checkPositive2([1, 2, 3, 4, 5]));

this doesn’t check for positive values, so no, they don’t do the same thing

But the difference between num => num > 0 and function(num) {return num > 0;} in this situation is only how many characters you are writing (there are situations in which function keyword syntax and arrow function syntax have different behaviour, but this is not the case)

oh, the first was an error…
thanks for the explanation of differences!!

First test says : Every element should be greater than 0.

Second test : Every element should be less than 10.

So test 1 passes for [5,6,11,9] but test2 will fail for this (because of 11).

Test1 fails for [-2,3] but test2 will pass here.

yeah the first was an error of typing my question was the difference between:

//this
 num => num > 0 
 //and this 
function(num) {return num > 0;}

but ilenia already answered me, thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.